You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Detected by experimental deadlock detector in cl/77450043.
==================
WARNING: DEADLOCK
Goroutine 999 lock mutex 11 while holding mutex 11:
sync.(*RWMutex).RLock()
src/pkg/sync/rwmutex.go:42 +0xa2
expvar.(*Map).String()
src/pkg/expvar/expvar.go:106 +0x77
expvar.TestMapCounter()
src/pkg/expvar/expvar_test.go:113 +0x53f
testing.tRunner()
src/pkg/testing/testing.go:422 +0x121
Mutex 11 was previously locked here:
sync.(*RWMutex).RLock()
src/pkg/sync/rwmutex.go:42 +0xa2
expvar.(*Map).Do()
src/pkg/expvar/expvar.go:203 +0x54
expvar.(*Map).String()
src/pkg/expvar/expvar.go:117 +0x1b4
expvar.TestMapCounter()
src/pkg/expvar/expvar_test.go:113 +0x53f
testing.tRunner()
src/pkg/testing/testing.go:422 +0x121
==================
In fact the following program crashes with "fatal error: all goroutines are asleep
- deadlock!":
http://play.golang.org/p/1uvDCFc0Vx
The problem is in the Map.String function that locks v.mu recursively (the second time
in v.Do):
func (v *Map) String() string {
v.mu.RLock()
defer v.mu.RUnlock()
var b bytes.Buffer
fmt.Fprintf(&b, "{")
first := true
v.Do(func(kv KeyValue) {
if !first {
fmt.Fprintf(&b, ", ")
}
fmt.Fprintf(&b, "\"%s\": %v", kv.Key, kv.Value)
first = false
})
fmt.Fprintf(&b, "}")
return b.String()
}
sync.RWMutex is not recursive for readers (and for writers)
.
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: