From 5eb16895cd436d1581f41328f01df5c65abd5776 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 20 Dec 2013 10:02:47 -0800 Subject: [PATCH] packer/rpc: use a pointer for maps to avoid race --- packer/rpc/muxconn.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packer/rpc/muxconn.go b/packer/rpc/muxconn.go index 04ce523f9..847e99329 100644 --- a/packer/rpc/muxconn.go +++ b/packer/rpc/muxconn.go @@ -200,11 +200,11 @@ func (m *MuxConn) NextId() uint32 { func (m *MuxConn) cleaner() { checks := []struct { - Map map[uint32]*Stream + Map *map[uint32]*Stream Lock *sync.RWMutex }{ - {m.streamsAccept, &m.muAccept}, - {m.streamsDial, &m.muDial}, + {&m.streamsAccept, &m.muAccept}, + {&m.streamsDial, &m.muDial}, } for { @@ -217,7 +217,7 @@ func (m *MuxConn) cleaner() { for _, check := range checks { check.Lock.Lock() - for id, s := range check.Map { + for id, s := range *check.Map { s.mu.Lock() if done && s.state != streamStateClosed { @@ -229,7 +229,7 @@ func (m *MuxConn) cleaner() { // for a certain amount of time. since := time.Now().UTC().Sub(s.stateUpdated) if since > 2*time.Second { - delete(check.Map, id) + delete(*check.Map, id) } }