Skip to content

srvutil: set default timeouts in NewServer - #276

Open
pior wants to merge 1 commit into
Shopify:mainfrom
pior:srvutil-timeouts-87036
Open

pior wants to merge 1 commit into
Shopify:mainfrom
pior:srvutil-timeouts-87036

Conversation

@pior

@pior pior commented Sep 25, 2026

Copy link
Copy Markdown
Member

Context

srvutil.NewServer builds an http.Server with only Addr and Handler. The Go zero value for the timeout fields means "no limit".
A client can send incomplete headers and keep the connection and its goroutine forever (Slowloris, CWE-400). Many such clients can use up the connections of the server.

Changes

  • NewServer sets ReadHeaderTimeout to 5s. This closes connections that do not finish the headers in time.
  • NewServer sets IdleTimeout to 120s. This closes idle keep-alive connections.
  • ReadTimeout and WriteTimeout stay unset. They also limit the request body and the handler, so they can break slow uploads or long responses of current callers.
  • The doc comments tell NewServerFromFactory callers to set at least ReadHeaderTimeout.
  • The //nolint:gosec suppression is removed, because gosec now accepts the literal.

@pior
pior marked this pull request as ready for review September 25, 2026 09:05
NewServer built an http.Server with no timeout fields. The Go zero
value means no limit, so a client that sends incomplete headers can
hold a connection open forever (Slowloris, CWE-400).

Set ReadHeaderTimeout to 5s and IdleTimeout to 120s. Callers that need
other values can use NewServerFromFactory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant