From dc519a539b86e69b7fc8cb869df74b53f7cbff5c Mon Sep 17 00:00:00 2001 From: alaviss Date: Wed, 12 Aug 2020 06:04:54 +0000 Subject: [PATCH] asyncnet: don't try to close the socket again [backport] (#15174) The closed flag isn't a good design by any means, but let's have this working first before I get rid of the flag and potentially create a non-backportable commit. (cherry picked from commit 957bf15a08d5443a50452909743747d19b5f29f8) --- lib/pure/asyncnet.nim | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/pure/asyncnet.nim b/lib/pure/asyncnet.nim index 88852fb84e..eea7a437a8 100644 --- a/lib/pure/asyncnet.nim +++ b/lib/pure/asyncnet.nim @@ -689,8 +689,12 @@ elif defined(nimdoc): proc close*(socket: AsyncSocket) = ## Closes the socket. + if socket.closed: return + defer: socket.fd.AsyncFD.closeSocket() + socket.closed = true # TODO: Add extra debugging checks for this. + when defineSsl: if socket.isSsl: let res = SSL_shutdown(socket.sslHandle) @@ -699,7 +703,6 @@ proc close*(socket: AsyncSocket) = discard elif res != 1: raiseSSLError() - socket.closed = true # TODO: Add extra debugging checks for this. when defineSsl: proc wrapSocket*(ctx: SslContext, socket: AsyncSocket) =