1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-10 02:35:58 +01:00

Store HTTP server in atomic.Value.

Keeps the race detector from complaining.
This commit is contained in:
Juliusz Chroboczek 2020-10-01 19:47:04 +02:00
parent 4ff1151fef
commit 0a49dc4569

View file

@ -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)
} }