packer/rpc: use a pointer for maps to avoid race

This commit is contained in:
Mitchell Hashimoto 2013-12-20 10:02:47 -08:00
parent 6ebfd502d7
commit 5eb16895cd
1 changed files with 5 additions and 5 deletions

View File

@ -200,11 +200,11 @@ func (m *MuxConn) NextId() uint32 {
func (m *MuxConn) cleaner() { func (m *MuxConn) cleaner() {
checks := []struct { checks := []struct {
Map map[uint32]*Stream Map *map[uint32]*Stream
Lock *sync.RWMutex Lock *sync.RWMutex
}{ }{
{m.streamsAccept, &m.muAccept}, {&m.streamsAccept, &m.muAccept},
{m.streamsDial, &m.muDial}, {&m.streamsDial, &m.muDial},
} }
for { for {
@ -217,7 +217,7 @@ func (m *MuxConn) cleaner() {
for _, check := range checks { for _, check := range checks {
check.Lock.Lock() check.Lock.Lock()
for id, s := range check.Map { for id, s := range *check.Map {
s.mu.Lock() s.mu.Lock()
if done && s.state != streamStateClosed { if done && s.state != streamStateClosed {
@ -229,7 +229,7 @@ func (m *MuxConn) cleaner() {
// for a certain amount of time. // for a certain amount of time.
since := time.Now().UTC().Sub(s.stateUpdated) since := time.Now().UTC().Sub(s.stateUpdated)
if since > 2*time.Second { if since > 2*time.Second {
delete(check.Map, id) delete(*check.Map, id)
} }
} }