Skip to content
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 racy code in Get #14

Merged
merged 1 commit into from
Jun 4, 2014
Merged

Fix racy code in Get #14

merged 1 commit into from
Jun 4, 2014

Conversation

LK4D4
Copy link
Contributor

@LK4D4 LK4D4 commented Jun 4, 2014

I was looking for races in docker and found this :)

@@ -31,8 31,9 @@ func Set(r *http.Request, key, val interface{}) {
func Get(r *http.Request, key interface{}) interface{} {
mutex.RLock()
if data[r] != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 👍 While you're here, can you change this to:

if ctx := data[r]; ctx != nil {
    value := ctx[key]
...

to avoid having to look up the key twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

kisielk added a commit that referenced this pull request Jun 4, 2014
@kisielk kisielk merged commit 14f550f into gorilla:master Jun 4, 2014
@kisielk
Copy link
Contributor

kisielk commented Jun 4, 2014

Thanks 👍

@LK4D4 LK4D4 deleted the fix_race_in_get branch June 4, 2014 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants