diff --git a/chronos/asyncloop.nim b/chronos/asyncloop.nim index 17588b3..2474b9d 100644 --- a/chronos/asyncloop.nim +++ b/chronos/asyncloop.nim @@ -629,8 +629,9 @@ elif unixPlatform: let loop = getGlobalDispatcher() proc continuation(udata: pointer) = - unregister(fd) - close(SocketHandle(fd)) + if SocketHandle(fd) in loop.selector: + unregister(fd) + close(SocketHandle(fd)) if not isNil(aftercb): aftercb(nil) diff --git a/chronos/transports/stream.nim b/chronos/transports/stream.nim index 15cd842..bc13c8d 100644 --- a/chronos/transports/stream.nim +++ b/chronos/transports/stream.nim @@ -722,8 +722,7 @@ when defined(windows): GC_unref(ovl) proc cancel(udata: pointer) {.gcsafe.} = - if not(retFuture.finished()): - sock.closeSocket() + sock.closeSocket() povl = RefCustomOverlapped() GC_ref(povl) @@ -1251,8 +1250,7 @@ else: retFuture.complete(transp) proc cancel(udata: pointer) {.gcsafe.} = - if not(retFuture.finished()): - closeSocket(sock) + closeSocket(sock) while true: var res = posix.connect(SocketHandle(sock),