From a64235dfeeade655d37bcfa2370688bf607141df Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Sat, 9 Nov 2024 18:51:10 +0700 Subject: [PATCH] only restart on specific errors --- ethers/providers/jsonrpc/subscriptions.nim | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/ethers/providers/jsonrpc/subscriptions.nim b/ethers/providers/jsonrpc/subscriptions.nim index eeb1931..0347e35 100644 --- a/ethers/providers/jsonrpc/subscriptions.nim +++ b/ethers/providers/jsonrpc/subscriptions.nim @@ -202,9 +202,18 @@ proc new*(_: type JsonRpcSubscriptions, proc keepAlivePolling = subscriptions.polling = poll() subscriptions.polling.catch(proc(e: ref CatchableError) = - trace "subscription polling loop failed, restarting", error = e.msg - startPolling() - trace "subscription polling loop restarted" + # ignore CancelledError, no need to bubble it + if e of RpcPostError: + discard sleepAsync(pollingInterval).then(proc() = + trace "restarting subscription polling loop" + subscriptions.polling = nil # release + keepAlivePolling() + trace "subscription polling loop restarted" + ) + else: + # What should we do here? + fatal "polling loop has failed", error = e.msg + raise newException(Defect, "polling loop has failed") ) keepAlivePolling()