Skip to content

Commit 6285d65

Browse files
authored
fix: remove (http.Server).ReadHeaderTimeout (#3730)
* fix: remove `(http.Server).ReadHeaderTimeout` Fixes #3710. It caused some race condition for websockets where the server sent the first message. * comment why disabled
1 parent 611ca55 commit 6285d65

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

cli/server.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -496,12 +496,16 @@ func Server(newAPI func(*coderd.Options) *coderd.API) *cobra.Command {
496496

497497
shutdownConnsCtx, shutdownConns := context.WithCancel(ctx)
498498
defer shutdownConns()
499+
500+
// ReadHeaderTimeout is purposefully not enabled. It caused some issues with
501+
// websockets over the dev tunnel.
502+
// See: https://github.com/coder/coder/pull/3730
503+
//nolint:gosec
499504
server := &http.Server{
500505
// These errors are typically noise like "TLS: EOF". Vault does similar:
501506
// https://github.com/hashicorp/vault/blob/e2490059d0711635e529a4efcbaa1b26998d6e1c/command/server.go#L2714
502-
ErrorLog: log.New(io.Discard, "", 0),
503-
Handler: coderAPI.Handler,
504-
ReadHeaderTimeout: time.Minute,
507+
ErrorLog: log.New(io.Discard, "", 0),
508+
Handler: coderAPI.Handler,
505509
BaseContext: func(_ net.Listener) context.Context {
506510
return shutdownConnsCtx
507511
},
@@ -1106,10 +1110,13 @@ func configureGithubOAuth2(accessURL *url.URL, clientID, clientSecret string, al
11061110
func serveHandler(ctx context.Context, logger slog.Logger, handler http.Handler, addr, name string) (closeFunc func()) {
11071111
logger.Debug(ctx, "http server listening", slog.F("addr", addr), slog.F("name", name))
11081112

1113+
// ReadHeaderTimeout is purposefully not enabled. It caused some issues with
1114+
// websockets over the dev tunnel.
1115+
// See: https://github.com/coder/coder/pull/3730
1116+
//nolint:gosec
11091117
srv := &http.Server{
1110-
Addr: addr,
1111-
Handler: handler,
1112-
ReadHeaderTimeout: time.Minute,
1118+
Addr: addr,
1119+
Handler: handler,
11131120
}
11141121
go func() {
11151122
err := srv.ListenAndServe()

coderd/httpmw/workspaceparam.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
"net/http"
99
"strings"
1010

11+
"github.com/go-chi/chi/v5"
12+
"github.com/google/uuid"
13+
1114
"github.com/coder/coder/coderd/database"
1215
"github.com/coder/coder/coderd/httpapi"
1316
"github.com/coder/coder/codersdk"
14-
"github.com/go-chi/chi/v5"
15-
"github.com/google/uuid"
1617
)
1718

1819
type workspaceParamContextKey struct{}
@@ -57,8 +58,8 @@ func ExtractWorkspaceParam(db database.Store) func(http.Handler) http.Handler {
5758
// "workspace_and_agent" URL parameter. `ExtractUserParam` must be called
5859
// before this.
5960
// This can be in the form of:
60-
// - "<workspace-name>.[workspace-agent]" : If multiple agents exist
61-
// - "<workspace-name>" : If one agent exists
61+
// - "<workspace-name>.[workspace-agent]" : If multiple agents exist
62+
// - "<workspace-name>" : If one agent exists
6263
func ExtractWorkspaceAndAgentParam(db database.Store) func(http.Handler) http.Handler {
6364
return func(next http.Handler) http.Handler {
6465
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy