Repository navigation
fix(humafiber): don't time out or panic in ServeHTTP - #1152
Merged
Merged
Conversation
ServeHTTP runs the request through Fiber's Test, which gives up after one second by default, and panics on any error it returns. Fiber doesn't recover panics by default, so a PATCH whose PUT handler took more than a second stopped a server that uses autopatch. Wait for the handler, and answer a remaining Test error with a 500.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1152 +/- ##
==========================================
- Coverage 94.73% 94.72% -0.01%
==========================================
Files 25 25
Lines 5200 5193 -7
==========================================
- Hits 4926 4919 -7
Misses 269 269
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
|
Thanks, this looks good. I checked the Fiber source: |
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.
With autopatch on Fiber, a PATCH whose PUT handler takes more than a second brings the server down:
The first PATCH ends the process with
panic: i/o timeout(panic: test: timeout error 1000mswithhumafiber.NewV2).autopatch sends its internal GET and PUT through the adapter's
ServeHTTP(autopatch.go#L317, #L449). Both Fiber adapters implement it with Fiber'sTest, which gives up after one second by default, and panic on any error it returns (humafiber.go#L261-L269, humafiber_v2.go#L263-L271). Fiber doesn't recover panics by default, so the panic stops the server.ServeHTTPnow turns the timeout off (TestConfig{Timeout: 0}on v3,-1on v2), so it waits for the handler like the net/http adapters do, and answers any otherTesterror with a 500 instead of panicking. The 500 has a generic body, since the error fromTestcan quote the raw request.This is the timeout and the panic left out of #1140.