fix: remove (http.Server).ReadHeaderTimeout (#3730)

* fix: remove `(http.Server).ReadHeaderTimeout`

Fixes https://github.com/coder/coder/issues/3710. It caused some race
condition for websockets where the server sent the first message.

* comment why disabled
This commit is contained in:
Colin Adler
2022-08-29 12:07:49 -05:00
committed by GitHub
parent 611ca55458
commit 6285d65b6a
2 changed files with 18 additions and 10 deletions
+13 -6
View File
@@ -496,12 +496,16 @@ func Server(newAPI func(*coderd.Options) *coderd.API) *cobra.Command {
shutdownConnsCtx, shutdownConns := context.WithCancel(ctx)
defer shutdownConns()
// ReadHeaderTimeout is purposefully not enabled. It caused some issues with
// websockets over the dev tunnel.
// See: https://github.com/coder/coder/pull/3730
//nolint:gosec
server := &http.Server{
// These errors are typically noise like "TLS: EOF". Vault does similar:
// https://github.com/hashicorp/vault/blob/e2490059d0711635e529a4efcbaa1b26998d6e1c/command/server.go#L2714
ErrorLog: log.New(io.Discard, "", 0),
Handler: coderAPI.Handler,
ReadHeaderTimeout: time.Minute,
ErrorLog: log.New(io.Discard, "", 0),
Handler: coderAPI.Handler,
BaseContext: func(_ net.Listener) context.Context {
return shutdownConnsCtx
},
@@ -1106,10 +1110,13 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
func serveHandler(ctx context.Context, logger slog.Logger, handler http.Handler, addr, name string) (closeFunc func()) {
logger.Debug(ctx, "http server listening", slog.F("addr", addr), slog.F("name", name))
// ReadHeaderTimeout is purposefully not enabled. It caused some issues with
// websockets over the dev tunnel.
// See: https://github.com/coder/coder/pull/3730
//nolint:gosec
srv := &http.Server{
Addr: addr,
Handler: handler,
ReadHeaderTimeout: time.Minute,
Addr: addr,
Handler: handler,
}
go func() {
err := srv.ListenAndServe()