mirror of
https://github.com/coder/coder.git
synced 2025-07-18 14:17:22 +00:00
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:
@ -496,12 +496,16 @@ func Server(newAPI func(*coderd.Options) *coderd.API) *cobra.Command {
|
|||||||
|
|
||||||
shutdownConnsCtx, shutdownConns := context.WithCancel(ctx)
|
shutdownConnsCtx, shutdownConns := context.WithCancel(ctx)
|
||||||
defer shutdownConns()
|
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{
|
server := &http.Server{
|
||||||
// These errors are typically noise like "TLS: EOF". Vault does similar:
|
// These errors are typically noise like "TLS: EOF". Vault does similar:
|
||||||
// https://github.com/hashicorp/vault/blob/e2490059d0711635e529a4efcbaa1b26998d6e1c/command/server.go#L2714
|
// https://github.com/hashicorp/vault/blob/e2490059d0711635e529a4efcbaa1b26998d6e1c/command/server.go#L2714
|
||||||
ErrorLog: log.New(io.Discard, "", 0),
|
ErrorLog: log.New(io.Discard, "", 0),
|
||||||
Handler: coderAPI.Handler,
|
Handler: coderAPI.Handler,
|
||||||
ReadHeaderTimeout: time.Minute,
|
|
||||||
BaseContext: func(_ net.Listener) context.Context {
|
BaseContext: func(_ net.Listener) context.Context {
|
||||||
return shutdownConnsCtx
|
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()) {
|
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))
|
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{
|
srv := &http.Server{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Handler: handler,
|
Handler: handler,
|
||||||
ReadHeaderTimeout: time.Minute,
|
|
||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
err := srv.ListenAndServe()
|
err := srv.ListenAndServe()
|
||||||
|
@ -8,11 +8,12 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
|
"github.com/google/uuid"
|
||||||
|
|
||||||
"github.com/coder/coder/coderd/database"
|
"github.com/coder/coder/coderd/database"
|
||||||
"github.com/coder/coder/coderd/httpapi"
|
"github.com/coder/coder/coderd/httpapi"
|
||||||
"github.com/coder/coder/codersdk"
|
"github.com/coder/coder/codersdk"
|
||||||
"github.com/go-chi/chi/v5"
|
|
||||||
"github.com/google/uuid"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type workspaceParamContextKey struct{}
|
type workspaceParamContextKey struct{}
|
||||||
@ -57,8 +58,8 @@ func ExtractWorkspaceParam(db database.Store) func(http.Handler) http.Handler {
|
|||||||
// "workspace_and_agent" URL parameter. `ExtractUserParam` must be called
|
// "workspace_and_agent" URL parameter. `ExtractUserParam` must be called
|
||||||
// before this.
|
// before this.
|
||||||
// This can be in the form of:
|
// This can be in the form of:
|
||||||
// - "<workspace-name>.[workspace-agent]" : If multiple agents exist
|
// - "<workspace-name>.[workspace-agent]" : If multiple agents exist
|
||||||
// - "<workspace-name>" : If one agent exists
|
// - "<workspace-name>" : If one agent exists
|
||||||
func ExtractWorkspaceAndAgentParam(db database.Store) func(http.Handler) http.Handler {
|
func ExtractWorkspaceAndAgentParam(db database.Store) func(http.Handler) http.Handler {
|
||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
|
||||||
|
Reference in New Issue
Block a user