-
Notifications
You must be signed in to change notification settings - Fork 8.1k
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
Fix context.Params race condition on Copy() #1841
Conversation
Using context.Param(key) on a context.Copy inside a goroutine may lead to incorrect value on a high load, where another request overwrite a Param
Codecov Report
@@ Coverage Diff @@
## master #1841 +/- ##
==========================================
+ Coverage 98.74% 98.75% +<.01%
==========================================
Files 38 38
Lines 2157 2160 +3
==========================================
+ Hits 2130 2133 +3
Misses 15 15
Partials 12 12
Continue to review full report at Codecov.
|
@samuelabreu would you mind converting your test case to use a
I'm not sure about others but, sleeps in test cases is a silly pet peeve of mine. Thank you very much for this test case. It highlights the race condition on master perfectly. 👍 |
@dmarkham, had to use 2 waitgroups, this is ok?
|
@samuelabreu Did you end up finding a edge case my version was not catching? I thought I had tested it well! So my question is why do you need 2? |
@dmarkham , when i tried it never fails the test. I think they run one goroutine after another, and to cause a race condition, the first assert must be executed after the second request. |
ok sorry I was sure I had something that was "clean" and "simple". I'll try to figure out what I was missing. I guess you should submit the version you like best at this point, I'm less excited about the |
@samuelabreu So for fun... I took your branch and deleted your fix :) and added all 3 versions of the test into the Travis... The good news is all 3 seem to fail in Travis! Maybe you would consider this hybrid approach:
|
@dmarkham, this version looks way better Im on a Mac, maybe it is something related to the OS scheduler running one after another on my setup and on travis (linux) running at the same time. I will update my branch, sync with upstream as soon as possible, thank you. |
@appleboy @javierprovecho @thinkerou This Looks like a pretty sold PR. Would one of you have a second for some feedback please. |
LGTM. Waiting for @thinkerou or @javierprovecho |
@samuelabreu @dangkaka Can you add some benchmark ? |
@appleboy @thinkerou I think this should get into |
* Fix context.Params race condition on Copy() Using context.Param(key) on a context.Copy inside a goroutine may lead to incorrect value on a high load, where another request overwrite a Param * Using waitgroup to wait asynchronous test case
Using context.Param(key) on a context.Copy inside a goroutine
may lead to incorrect value on a high load, where another request
overwrite a Param
master