From 9af56363a72d2e9f29d444682583074e4d05a213 Mon Sep 17 00:00:00 2001 From: Alexandr Morozov Date: Wed, 4 Jun 2014 18:45:55 +0400 Subject: [PATCH] Fix racy code in Get --- context.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/context.go b/context.go index 2a7357f..81cb128 100644 --- a/context.go +++ b/context.go @@ -30,9 +30,10 @@ func Set(r *http.Request, key, val interface{}) { // Get returns a value stored for a given key in a given request. func Get(r *http.Request, key interface{}) interface{} { mutex.RLock() - if data[r] != nil { + if ctx := data[r]; ctx != nil { + value := ctx[key] mutex.RUnlock() - return data[r][key] + return value } mutex.RUnlock() return nil