From db8b4cad4aa50348423757ed963853d6c9876449 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Thu, 21 Dec 2017 21:49:31 +0100 Subject: [PATCH] server: fix deadlock in sendToPeer at peer shutdown This commit fixes a deadlock that could occur when a peer disconnected during a call to sentToPeer. In This particular case, a message would successfully be queued, the peer would shutdown, and we would block waiting for an error to be returned on the message's error channel, which would deadlock. This fixes that by also checking for peer shutdown. --- server.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server.go b/server.go index ab049366..692e59b3 100644 --- a/server.go +++ b/server.go @@ -958,6 +958,8 @@ func (s *server) sendToPeer(target *btcec.PublicKey, select { case err := <-errChan: return err + case <-targetPeer.quit: + return fmt.Errorf("peer shutting down") case <-s.quit: return ErrServerShuttingDown }