File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ type Muxer struct {
2222 sendMutex sync.Mutex
2323 startChan chan bool
2424 doneChan chan bool
25+ stopMutex sync.Mutex
2526 ErrorChan chan error
2627 protocolSenders map [uint16 ]chan * Segment
2728 protocolReceivers map [uint16 ]chan * Segment
@@ -45,21 +46,25 @@ func (m *Muxer) Start() {
4546}
4647
4748func (m * Muxer ) Stop () {
49+ // We use a mutex to prevent this function from being called multiple times
50+ // concurrently, which would cause a race condition
51+ m .stopMutex .Lock ()
52+ defer m .stopMutex .Unlock ()
4853 // Immediately return if we're already shutting down
4954 select {
5055 case <- m .doneChan :
5156 return
5257 default :
5358 }
59+ // Close doneChan to signify that we're shutting down
60+ close (m .doneChan )
5461 // Close protocol receive channels
5562 // We rely on the individual mini-protocols to close the sender channel
5663 for _ , recvChan := range m .protocolReceivers {
5764 close (recvChan )
5865 }
5966 // Close ErrorChan to signify to consumer that we're shutting down
6067 close (m .ErrorChan )
61- // Close doneChan to signify that we're shutting down
62- close (m .doneChan )
6368}
6469
6570func (m * Muxer ) sendError (err error ) {
You can’t perform that action at this time.
0 commit comments