-
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
"concurrent map read and map write" in getting context #700
Comments
is the Context often used as a container or something else? |
Yes, it is used as a map to store header values and some request metrics |
okay, uh, so the Context is commonly used as a single entity. well, we should use Mutex in our logic instead of directly bind a Mutex to the Contexts. |
Should we orient ourselves toward context.Context? It is safe to use concurrently and gin.Context implements the interface. |
any update on this issue? |
As I just commented in pull request #702, putting a Mutex around c.Keys is a bad idea due to the recycling logic gin gonic applies to Context instances. |
Because of the recycling logic gin applies to Context, we can not simply use gin.Context and must do c.Copy for continue use(may be used in a goroutine), and this result that we do c.Copy nearly almost every method. Just thinking about we need an option to disable recycling logic for gin.Context. |
Not sure if anyone started getting this issue with Go 1.8, but we did - a lot. (We just deployed to production with 1.8 for the first time today.) Looks like 1.8 added a new check. From https://stackoverflow.com/questions/42453442/concurrent-map-iteration-and-map-write-error-in-golang-1-8 :
I'm trying to work around it right now, but I may be forced to toss a mutex lock into our vendor copy of Gin in the meantime (or roll back to 1.7)... |
FYI This issue should be closed |
set header 、 set response , is it safe too? |
I find this question @v1.4.0, question could go to sleep finally. Thx this issue. |
set header is also not concurrent write safe, can lead to: |
I got a race condition when getting value from
Context
:concurrent map read and map write
The potential error code is in
/gin-gonic/gin/context.go
I thought here we must use Mutex around
c.Keys[key]
to avoid the race condition.The text was updated successfully, but these errors were encountered: