From 0a5d6118c2fa860dec600cc46e6ee2fa2ae6fa7c Mon Sep 17 00:00:00 2001 From: kdeme Date: Fri, 21 Jun 2019 11:14:00 +0200 Subject: [PATCH] Add check if message loop is finished during connection stage --- eth/p2p/rlpx.nim | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/eth/p2p/rlpx.nim b/eth/p2p/rlpx.nim index 77a388a..900420e 100644 --- a/eth/p2p/rlpx.nim +++ b/eth/p2p/rlpx.nim @@ -1291,6 +1291,13 @@ proc postHelloSteps(peer: Peer, h: devp2p.hello) {.async.} = # await all(subProtocolsHandshakes) + # This is needed as a peer might have already disconnected. In this case + # we need to raise so that rlpxConnect/rlpxAccept fails. + # Disconnect is done only to run the disconnect handlers. TODO: improve this + # also TODO: Should we discern the type of error? + if messageProcessingLoop.finished: + await peer.disconnectAndRaise(ClientQuitting, + "messageProcessingLoop ended while connecting") peer.connectionState = Connected template `^`(arr): auto =