mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Store HTTP server in atomic.Value.
Keeps the race detector from complaining.
This commit is contained in:
parent
4ff1151fef
commit
0a49dc4569
1 changed files with 13 additions and 5 deletions
|
@ -15,6 +15,7 @@ import (
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
@ -25,7 +26,7 @@ import (
|
||||||
"sfu/stats"
|
"sfu/stats"
|
||||||
)
|
)
|
||||||
|
|
||||||
var server *http.Server
|
var server atomic.Value
|
||||||
|
|
||||||
var StaticRoot string
|
var StaticRoot string
|
||||||
|
|
||||||
|
@ -50,19 +51,21 @@ func Serve(address string, dataDir string) error {
|
||||||
statsHandler(w, r, dataDir)
|
statsHandler(w, r, dataDir)
|
||||||
})
|
})
|
||||||
|
|
||||||
server = &http.Server{
|
s := &http.Server{
|
||||||
Addr: address,
|
Addr: address,
|
||||||
ReadHeaderTimeout: 60 * time.Second,
|
ReadHeaderTimeout: 60 * time.Second,
|
||||||
IdleTimeout: 120 * time.Second,
|
IdleTimeout: 120 * time.Second,
|
||||||
}
|
}
|
||||||
server.RegisterOnShutdown(func() {
|
s.RegisterOnShutdown(func() {
|
||||||
group.Range(func(g *group.Group) bool {
|
group.Range(func(g *group.Group) bool {
|
||||||
go g.Shutdown("server is shutting down")
|
go g.Shutdown("server is shutting down")
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
err := server.ListenAndServeTLS(
|
server.Store(s)
|
||||||
|
|
||||||
|
err := s.ListenAndServeTLS(
|
||||||
filepath.Join(dataDir, "cert.pem"),
|
filepath.Join(dataDir, "cert.pem"),
|
||||||
filepath.Join(dataDir, "key.pem"),
|
filepath.Join(dataDir, "key.pem"),
|
||||||
)
|
)
|
||||||
|
@ -582,7 +585,12 @@ func serveGroupRecordings(w http.ResponseWriter, r *http.Request, f *os.File, gr
|
||||||
}
|
}
|
||||||
|
|
||||||
func Shutdown() {
|
func Shutdown() {
|
||||||
|
v := server.Load()
|
||||||
|
if v == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
s := v.(*http.Server)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
server.Shutdown(ctx)
|
s.Shutdown(ctx)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue