From ce115a6a59f9e04107befac2301521e63077b4a2 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 24 Aug 2018 17:49:12 -0700 Subject: [PATCH] peer: raise readHandler wait group done to defer statement In this commit, we raise the readHandler wait group done into a defer statement at the top of the method. This fixes an existing but that would cause the readHandler to declare it had exited, yet possibly still be waiting on the chan message stream below to exit. --- peer.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/peer.go b/peer.go index a49a3cf7e..7c979f858 100644 --- a/peer.go +++ b/peer.go @@ -878,6 +878,7 @@ func newDiscMsgStream(p *peer) *msgStream { // // NOTE: This method MUST be run as a goroutine. func (p *peer) readHandler() { + defer p.wg.Done() // We'll stop the timer after a new messages is received, and also // reset it after we process the next message. @@ -1066,8 +1067,6 @@ out: idleTimer.Reset(idleTimeout) } - p.wg.Done() - p.Disconnect(errors.New("read handler closed")) for cid, chanStream := range chanMsgStreams {