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,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()