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) =