Reconcile HTTP WriteTimeout with the request middleware timeout #62
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Part of the road to 1.0 (see #33).
internal/server/http.gosetsWriteTimeout = 10son thehttp.Server, whileinternal/server/routes.goappliesmiddleware.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:
WriteTimeoutto at least the middleware timeout, or lower the middleware timeout to matchWriteTimeout— with a code comment explaining the chosen maximum request durationImplementation instructions
Confine this change to
internal/server/http.goONLY. Do NOT editinternal/server/routes.go— another change is in flight there, andrequestTimeout(60s) stays the source of truth for the request budget.The problem:
http.gosetshttpWriteTimeout = 10s, while the router appliesmiddleware.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:
httpWriteTimeoutto comfortably exceed the 60s request timeout — use65 * time.Second— so the middleware timeout becomes the effective limit and returns a proper 503, instead of the transport killing the connectionhttpReadTimeout(10s) unchangedhttpWriteTimeoutnoting it must stay above the router'srequestTimeout(60s) so the middleware timeout winsDefinition of done:
httpWriteTimeoutis greater than the 60s request middleware timeout, with a comment explaining the relationshipinternal/server/http.gois changedGates and process:
make fmtbefore committinggo.modneeds 1.26, so validate withdocker build .(must exit 0; runs fmt-check, lint, test, build)mainnamedissue-62-write-timeout; commit subject ends with(closes #62)main) and comment on it with the diff summary and thedocker build .result