fix: preserve timeout without pooled context reuse#222
Open
hwbrzzl wants to merge 3 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adjusts the Gin driver’s timeout middleware to avoid running the request chain in a background goroutine, preventing pooled context/request/response wrappers from being reused while downstream handlers are still executing (fixing cross-request write contamination after timeouts).
Changes:
- Run the timeout middleware’s request chain synchronously to avoid use-after-pool-reuse.
- Ensure
ctx.Done(),ctx.Err(), andctx.Deadline()reflect the request context installed by the timeout middleware. - Add regression tests covering a timed-out request followed by a normal request to ensure late writes don’t leak across requests.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| middleware_timeout.go | Removes background goroutine execution; runs Next() synchronously after installing a timed context. |
| middleware_timeout_test.go | Adds concurrency/regression tests validating timeout observation and isolation across requests. |
| context.go | Routes Deadline/Done/Err through the request context to reflect middleware-installed context. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
hwbrzzl
commented
May 23, 2026
Contributor
Author
There was a problem hiding this comment.
Are the changes still needed?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
gin-contrib/timeoutinternally.408 Request Timeoutresponses while preventing late writes from a timed-out request from leaking into the next request.Closes goravel/goravel#966
Why
The previous timeout middleware enforced timeouts by running the Gin chain in a background goroutine and returning as soon as the deadline fired. That made Goravel return pooled request and response wrappers before the timed-out handler had actually stopped, which could let late writes bleed into a later request.
This change keeps the timeout feature instead of removing it. Goravel still exposes the same
Timeout(...)middleware and still returns HTTP 408 on timeout, but the implementation now delegates togin-contrib/timeout, which buffers the response, suppresses late writes after timeout, and waits for the worker goroutine to finish before control returns to Gin's pooled context lifecycle.