Skip to content

Commit

Permalink
Fixed dmsg closing logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
林志宇 committed Jun 2, 2019
1 parent 3fc9d28 commit 43f5a6e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pkg/dmsg/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,19 @@ func NewTransport(conn net.Conn, log *logging.Logger, local, remote cipher.PubKe

func (c *Transport) close() (closed bool) {
c.doneOnce.Do(func() {
close(c.doneCh)
closed = true
close(c.doneCh)

// Kill all goroutines pushing to `c.readCh` before closing it.
// No more goroutines pushing to `c.readCh` should be created once `c.doneCh` is closed.
for {
select {
case <-c.readCh:
default:
close(c.readCh)
return
}
}
})
return closed
}
Expand Down Expand Up @@ -122,7 +133,7 @@ func (c *Transport) InjectRead(f Frame) bool {
ok := c.injectRead(f)
if !ok {
c.close()
close(c.readCh)
//close(c.readCh)
}
return ok
}
Expand Down

0 comments on commit 43f5a6e

Please sign in to comment.