fix harmless race where the same value is written to a tls config concurrently

This commit is contained in:
Mechiel Lukkien 2024-04-15 20:07:39 +02:00
parent 11eaa8cd1a
commit e1dbc07dba
No known key found for this signature in database
2 changed files with 6 additions and 2 deletions

View file

@ -21,6 +21,9 @@ build1:
install: build0 frontend install: build0 frontend
CGO_ENABLED=0 go install CGO_ENABLED=0 go install
race: build0
go build -race
test: test:
CGO_ENABLED=0 go test -shuffle=on -coverprofile cover.out ./... CGO_ENABLED=0 go test -shuffle=on -coverprofile cover.out ./...
go tool cover -html=cover.out -o cover.html go tool cover -html=cover.out -o cover.html

View file

@ -773,7 +773,8 @@ func listen1(ip string, port int, tlsConfig *tls.Config, name string, kinds []st
server := &http.Server{ server := &http.Server{
Handler: handler, Handler: handler,
TLSConfig: tlsConfig, // Clone because our multiple Server.Serve calls modify config concurrently leading to data race.
TLSConfig: tlsConfig.Clone(),
ReadHeaderTimeout: 30 * time.Second, ReadHeaderTimeout: 30 * time.Second,
IdleTimeout: 65 * time.Second, // Chrome closes connections after 60 seconds, firefox after 115 seconds. IdleTimeout: 65 * time.Second, // Chrome closes connections after 60 seconds, firefox after 115 seconds.
ErrorLog: golog.New(mlog.LogWriter(pkglog.With(slog.String("pkg", "net/http")), slog.LevelInfo, protocol+" error"), "", 0), ErrorLog: golog.New(mlog.LogWriter(pkglog.With(slog.String("pkg", "net/http")), slog.LevelInfo, protocol+" error"), "", 0),