-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move timeout handling into handlers. #786
Conversation
What does this fix? |
There are strange race conditions that cause response writers to get mixed up. It seems to be a result of the TimeoutMiddleware, I was able to reproduce some strange behaviors and panics in a unit test. There are many discussions on github about people finding different data race conditions, and pretty much giving up on the middleware. Here is one: labstack/echo#1947 (comment) |
Thanks for the link. Why not do this? https://github.com/labstack/echo/pull/1947/files#diff-d2f7e13f33e9dc860e88548eb3886115c7876523f7b030da18a6f157663e2487R20 |
I updated to the latest version of echo and was still able to reproduce some problems with this middleware. After disabling the middleware all issues went away. The way echo passes around the shared context is very convenient for most normal HTTP server things, but seems to be problematic if the middleware needs to do things later on. In this case, after a timeout. |
But the example I pointed out is a custom middleware. Does it also not work? |
That custom middleware is what we were using. There are some rare race conditions in it. |
No, we were using a middleware from the |
@tolikzinovyev I see. I'm having some trouble getting |
Codecov Report
@@ Coverage Diff @@
## develop #786 +/- ##
===========================================
+ Coverage 54.37% 58.53% +4.15%
===========================================
Files 28 29 +1
Lines 3908 4001 +93
===========================================
+ Hits 2125 2342 +217
+ Misses 1499 1364 -135
- Partials 284 295 +11
Continue to review full report at Codecov.
|
@winder can you add in PR description how you validated/tested the change / what the behavior is intended to do? |
304e027
to
1a0d937
Compare
return errors.New("should not return") | ||
}) | ||
|
||
require.Error(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this shouldn't be necessary also
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with this one, it ensures that there's no panic if a subsequent check assumes the error is not nil. Maybe ErrorIs
handles the nil case, or maybe not.
Summary
Replace echo TimeoutMiddleware with timeout handling in handlers. The behavior is functionally identical to the previous implementation, but no longer contains concurrency primitives spanning multiple handler functions.
Test Plan
CallWithTimeout
utility.make integration
,make e2e
, and integration go tests all use this code path.