packer/rpc: fix data race by acquiring wrong locks in MuxConn

This commit is contained in:
Mitchell Hashimoto 2013-12-20 09:55:57 -08:00
parent 9b579a9dd7
commit 6ebfd502d7
1 changed files with 4 additions and 3 deletions

View File

@ -26,7 +26,6 @@ type MuxConn struct {
rwc io.ReadWriteCloser
streamsAccept map[uint32]*Stream
streamsDial map[uint32]*Stream
mu sync.RWMutex
muAccept sync.RWMutex
muDial sync.RWMutex
wlock sync.Mutex
@ -78,8 +77,10 @@ func NewMuxConn(rwc io.ReadWriteCloser) *MuxConn {
// Close closes the underlying io.ReadWriteCloser. This will also close
// all streams that are open.
func (m *MuxConn) Close() error {
m.mu.Lock()
defer m.mu.Unlock()
m.muAccept.Lock()
m.muDial.Lock()
defer m.muAccept.Unlock()
defer m.muDial.Unlock()
// Close all the streams
for _, w := range m.streamsAccept {