From cea23299be35162cce12573dbd20fbc7eec9da20 Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Thu, 15 Jun 2023 04:26:22 -0600 Subject: [PATCH] Avoid double socket destroy on timed-out uTP SYN-ACK (#619) --- eth/utp/utp_socket.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/eth/utp/utp_socket.nim b/eth/utp/utp_socket.nim index 3c81ab9..e93d723 100644 --- a/eth/utp/utp_socket.nim +++ b/eth/utp/utp_socket.nim @@ -576,9 +576,13 @@ proc checkTimeouts(socket: UtpSocket) = retransmitCount = socket.retransmitCount if socket.state == SynSent and (not socket.connectionFuture.finished()): - socket.connectionFuture.fail(newException(ConnectionError, "Connection to peer timed out")) + # Note: The socket connect code will already call socket.destroy when + # ConnectionError gets raised, no need to do it here. + socket.connectionFuture.fail(newException( + ConnectionError, "Connection to peer timed out")) + else: + socket.destroy() - socket.destroy() return let newTimeout = socket.retransmitTimeout * 2