-
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.Copy() race condition #1020
Fix context.Copy() race condition #1020
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1020 +/- ##
==========================================
+ Coverage 98.49% 98.49% +<.01%
==========================================
Files 41 41
Lines 2059 2062 +3
==========================================
+ Hits 2028 2031 +3
Misses 19 19
Partials 12 12
Continue to review full report at Codecov.
|
@furmmon can you add a test at |
88dc66c
to
17ddb4a
Compare
Sure, couldn't find a simple test for that at first. This test fails on the current master |
041b45b
to
52958eb
Compare
@javierprovecho this seems like a fairly important thing to fix in a trivial set of changes - any plans on getting it in? |
hey @appleboy, this is still an existing problem with the gin-gonic library, could you take a look at it |
Hi @furmmon you can add the following test code:
If use old gin, the case will panics, I don't know how to catch the panics using |
@appleboy please review the pr, thanks! |
This PR aims to point an existing race condition with the gin.Context and propose a solution.
The gin.Context stores keys in a
map[string]interface{}
. The function gin.Context.Copy() (context.go:79) is supposed to give a thread safe copy of the initial gin.Context.Instead of making a proper copy of the context.Keys, it copies the references of the map. This creates a race condition whenever the map context.Keys is accessed by concurrent go-routines.
With the following script you will get the raise condition instantly. The fix in the PR will solve it.