From d6e55ca3d8aa09af1da9303da85385b5b3c1ec3b Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Fri, 19 Jan 2024 08:18:02 +0100 Subject: [PATCH] fix improper `yield` usage in `el_manager` (#5789) `yield` is not supported in `{.async.}`. Replace with alternative that does not leak. --- beacon_chain/el/el_manager.nim | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/beacon_chain/el/el_manager.nim b/beacon_chain/el/el_manager.nim index 70829a180..a7021b4c7 100644 --- a/beacon_chain/el/el_manager.nim +++ b/beacon_chain/el/el_manager.nim @@ -583,17 +583,14 @@ proc newWeb3*(engineUrl: EngineApiUrl): Future[Web3] = proc establishEngineApiConnection*(url: EngineApiUrl): Future[Result[Web3, string]] {.async.} = - let web3Fut = newWeb3(url) - yield web3Fut or sleepAsync(engineApiConnectionTimeout) - - if not web3Fut.completed: - await cancelAndWait(web3Fut) - if web3Fut.failed: - return err "Failed to setup Engine API connection: " & web3Fut.readError.msg - else: - return err "Failed to setup Engine API connection" - else: - return ok web3Fut.read + try: + ok(await newWeb3(url).wait(engineApiConnectionTimeout)) + except AsyncTimeoutError: + err "Engine API connection timed out" + except CancelledError as exc: + raise exc + except CatchableError as exc: + err "Engine API connection failed: " & exc.msg proc tryConnecting(connection: ELConnection): Future[bool] {.async.} = if connection.isConnected: