Skip to content

Commit 3713aa0

Browse files
authored
Merge pull request #270 from blinklabs-io/fix/muxer-stop-deadlock
fix: close connection on muxer stop
2 parents 3066190 + 9fafa3e commit 3713aa0

File tree

3 files changed

+4
-6
lines changed

3 files changed

+4
-6
lines changed

internal/test/ouroboros_mock/connection.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func (c *Connection) Write(b []byte) (n int, err error) {
7070

7171
// Close closes both sides of the connection. This is needed to satisfy the net.Conn interface
7272
func (c *Connection) Close() error {
73+
c.muxer.Stop()
7374
if err := c.conn.Close(); err != nil {
7475
return err
7576
}

muxer/muxer.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ func (m *Muxer) Stop() {
8888
m.onceStop.Do(func() {
8989
// Close doneChan to signify that we're shutting down
9090
close(m.doneChan)
91+
// Close underlying connection
92+
// We must do this to break out of pending Read() calls to shut down cleanly
93+
_ = m.conn.Close()
9194
// Wait for other goroutines to shutdown
9295
m.waitGroup.Wait()
9396
// Close protocol receive channels

ouroboros.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ func (o *Ouroboros) Close() error {
138138
if o.muxer != nil {
139139
o.muxer.Stop()
140140
}
141-
// Close the underlying connection
142-
if o.conn != nil {
143-
if err = o.conn.Close(); err != nil {
144-
return
145-
}
146-
}
147141
// Wait for other goroutines to finish
148142
o.waitGroup.Wait()
149143
// Close channels

0 commit comments

Comments
 (0)