Reconcile HTTP WriteTimeout with the request middleware timeout #62

Closed
opened 2026-08-07 13:10:59 +02:00 by clawbot · 1 comment
Collaborator

Part of the road to 1.0 (see #33).

internal/server/http.go sets WriteTimeout = 10s on the http.Server, while internal/server/routes.go applies middleware.Timeout(60s) (requestTimeout). The 10s socket write deadline always fires first, so the 60s middleware timeout can never take effect and any response taking longer than 10s is cut off at the transport layer.

Definition of done:

  • the two timeouts are made consistent — either raise WriteTimeout to at least the middleware timeout, or lower the middleware timeout to match WriteTimeout — with a code comment explaining the chosen maximum request duration
  • the intended maximum request duration is documented in one place
  • no regression in existing server/middleware tests
Part of the road to 1.0 (see #33). `internal/server/http.go` sets `WriteTimeout = 10s` on the `http.Server`, while `internal/server/routes.go` applies `middleware.Timeout(60s)` (`requestTimeout`). The 10s socket write deadline always fires first, so the 60s middleware timeout can never take effect and any response taking longer than 10s is cut off at the transport layer. Definition of done: - the two timeouts are made consistent — either raise `WriteTimeout` to at least the middleware timeout, or lower the middleware timeout to match `WriteTimeout` — with a code comment explaining the chosen maximum request duration - the intended maximum request duration is documented in one place - no regression in existing server/middleware tests
clawbot added this to the 1.0.0 milestone 2026-08-07 13:10:59 +02:00
Author
Collaborator

Implementation instructions

Confine this change to internal/server/http.go ONLY. Do NOT edit internal/server/routes.go — another change is in flight there, and requestTimeout (60s) stays the source of truth for the request budget.

The problem: http.go sets httpWriteTimeout = 10s, while the router applies middleware.Timeout(60s). The 10s socket write deadline fires first, so a slow response is cut at the transport layer before the 60s middleware timeout can return a clean 503.

Fix:

  • raise httpWriteTimeout to comfortably exceed the 60s request timeout — use 65 * time.Second — so the middleware timeout becomes the effective limit and returns a proper 503, instead of the transport killing the connection
  • leave httpReadTimeout (10s) unchanged
  • add a code comment on httpWriteTimeout noting it must stay above the router's requestTimeout (60s) so the middleware timeout wins

Definition of done:

  • httpWriteTimeout is greater than the 60s request middleware timeout, with a comment explaining the relationship
  • only internal/server/http.go is changed
  • existing server tests still pass

Gates and process:

  • make fmt before committing
  • host Go is 1.25 but go.mod needs 1.26, so validate with docker build . (must exit 0; runs fmt-check, lint, test, build)
  • branch from main named issue-62-write-timeout; commit subject ends with (closes #62)
  • open a PR (base main) and comment on it with the diff summary and the docker build . result
  • no AI-assistant/tooling references anywhere
## Implementation instructions Confine this change to `internal/server/http.go` ONLY. Do NOT edit `internal/server/routes.go` — another change is in flight there, and `requestTimeout` (60s) stays the source of truth for the request budget. The problem: `http.go` sets `httpWriteTimeout = 10s`, while the router applies `middleware.Timeout(60s)`. The 10s socket write deadline fires first, so a slow response is cut at the transport layer before the 60s middleware timeout can return a clean 503. Fix: - raise `httpWriteTimeout` to comfortably exceed the 60s request timeout — use `65 * time.Second` — so the middleware timeout becomes the effective limit and returns a proper 503, instead of the transport killing the connection - leave `httpReadTimeout` (10s) unchanged - add a code comment on `httpWriteTimeout` noting it must stay above the router's `requestTimeout` (60s) so the middleware timeout wins Definition of done: - `httpWriteTimeout` is greater than the 60s request middleware timeout, with a comment explaining the relationship - only `internal/server/http.go` is changed - existing server tests still pass Gates and process: - `make fmt` before committing - host Go is 1.25 but `go.mod` needs 1.26, so validate with `docker build .` (must exit 0; runs fmt-check, lint, test, build) - branch from `main` named `issue-62-write-timeout`; commit subject ends with ` (closes #62)` - open a PR (base `main`) and comment on it with the diff summary and the `docker build .` result - no AI-assistant/tooling references anywhere
sneak closed this issue 2026-08-07 13:58:29 +02:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/webhooker#62