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
CGO_ENABLED=0 go install
race: build0
go build -race
test:
CGO_ENABLED=0 go test -shuffle=on -coverprofile cover.out ./...
go tool cover -html=cover.out -o cover.html

View file

@ -772,8 +772,9 @@ func listen1(ip string, port int, tlsConfig *tls.Config, name string, kinds []st
}
server := &http.Server{
Handler: handler,
TLSConfig: tlsConfig,
Handler: handler,
// Clone because our multiple Server.Serve calls modify config concurrently leading to data race.
TLSConfig: tlsConfig.Clone(),
ReadHeaderTimeout: 30 * time.Second,
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),