only restart on specific errors

This commit is contained in:
Eric 2024-11-09 18:51:10 +07:00
parent 022b97b5ce
commit a64235dfee
No known key found for this signature in database

View File

@ -202,10 +202,19 @@ proc new*(_: type JsonRpcSubscriptions,
proc keepAlivePolling = proc keepAlivePolling =
subscriptions.polling = poll() subscriptions.polling = poll()
subscriptions.polling.catch(proc(e: ref CatchableError) = subscriptions.polling.catch(proc(e: ref CatchableError) =
trace "subscription polling loop failed, restarting", error = e.msg # ignore CancelledError, no need to bubble it
startPolling() if e of RpcPostError:
discard sleepAsync(pollingInterval).then(proc() =
trace "restarting subscription polling loop"
subscriptions.polling = nil # release
keepAlivePolling()
trace "subscription polling loop restarted" 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() keepAlivePolling()
subscriptions subscriptions