From 55b9da0bea5dde89a160d43cdc469210dd481720 Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 2 Jun 2023 14:33:06 +0200 Subject: [PATCH] fix cancellation syntax (#615) * fix cancellation syntax * simplify --- eth/utp/utp_router.nim | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/eth/utp/utp_router.nim b/eth/utp/utp_router.nim index e4391e6..906663b 100644 --- a/eth/utp/utp_router.nim +++ b/eth/utp/utp_router.nim @@ -284,10 +284,8 @@ proc generateNewUniqueSocket[A]( return none[UtpSocket[A]]() proc innerConnect[A](s: UtpSocket[A]): Future[ConnectionResult[A]] {.async.} = - let startFut = s.startOutgoingSocket() - try: - await startFut + await s.startOutgoingSocket() utp_success_outgoing.inc() debug "Outgoing connection successful", dst = s.socketKey return ok(s) @@ -304,18 +302,7 @@ proc innerConnect[A](s: UtpSocket[A]): Future[ConnectionResult[A]] {.async.} = proc connect[A](s: UtpSocket[A]): Future[ConnectionResult[A]] = debug "Initiating connection", dst = s.socketKey - # Create inner future, to make sure we are installing cancelCallback - # on whole connection future, and not only part of it - let connectionFuture = s.innerConnect() - - connectionFuture.cancelCallback = proc(udata: pointer) {.gcsafe.} = - debug "Connection cancel callback fired", - socketKey = s.socketKey - # if for some reason the future is cancelled, destroy socket to clear it - # from the active socket list - s.destroy() - - return connectionFuture + s.innerConnect() proc socketAlreadyExists[A](): ConnectionResult[A] = return err(OutgoingConnectionError(kind: SocketAlreadyExists))