gracefully unsubscribe without errors
During shutdown sequence, KeyErrors were being reported for subscriptions. We can safely ignore these if the subscription already doesn't exist.
This commit is contained in:
parent
dba7e5508c
commit
022b97b5ce
|
@ -69,7 +69,7 @@ method subscribeLogs*(subscriptions: JsonRpcSubscriptions,
|
||||||
|
|
||||||
method unsubscribe*(subscriptions: JsonRpcSubscriptions,
|
method unsubscribe*(subscriptions: JsonRpcSubscriptions,
|
||||||
id: JsonNode)
|
id: JsonNode)
|
||||||
{.async, base.} =
|
{.async: (raises: [CancelledError]), base.} =
|
||||||
raiseAssert "not implemented"
|
raiseAssert "not implemented"
|
||||||
|
|
||||||
method close*(subscriptions: JsonRpcSubscriptions) {.async, base.} =
|
method close*(subscriptions: JsonRpcSubscriptions) {.async, base.} =
|
||||||
|
@ -128,9 +128,15 @@ method subscribeLogs(subscriptions: WebSocketSubscriptions,
|
||||||
|
|
||||||
method unsubscribe*(subscriptions: WebSocketSubscriptions,
|
method unsubscribe*(subscriptions: WebSocketSubscriptions,
|
||||||
id: JsonNode)
|
id: JsonNode)
|
||||||
{.async.} =
|
{.async: (raises: [CancelledError]).} =
|
||||||
subscriptions.callbacks.del(id)
|
try:
|
||||||
discard await subscriptions.client.eth_unsubscribe(id)
|
subscriptions.callbacks.del(id)
|
||||||
|
discard await subscriptions.client.eth_unsubscribe(id)
|
||||||
|
except CancelledError as e:
|
||||||
|
raise e
|
||||||
|
except KeyError, CatchableError:
|
||||||
|
# Ignore if uninstallation of the filter fails.
|
||||||
|
discard
|
||||||
|
|
||||||
# Polling
|
# Polling
|
||||||
|
|
||||||
|
@ -249,16 +255,16 @@ method subscribeLogs(subscriptions: PollingSubscriptions,
|
||||||
|
|
||||||
method unsubscribe*(subscriptions: PollingSubscriptions,
|
method unsubscribe*(subscriptions: PollingSubscriptions,
|
||||||
id: JsonNode)
|
id: JsonNode)
|
||||||
{.async.} =
|
{.async: (raises: [CancelledError]).} =
|
||||||
subscriptions.logFilters.del(id)
|
|
||||||
subscriptions.callbacks.del(id)
|
|
||||||
let sub = subscriptions.subscriptionMapping[id]
|
|
||||||
subscriptions.subscriptionMapping.del(id)
|
|
||||||
try:
|
try:
|
||||||
|
subscriptions.logFilters.del(id)
|
||||||
|
subscriptions.callbacks.del(id)
|
||||||
|
let sub = subscriptions.subscriptionMapping[id]
|
||||||
|
subscriptions.subscriptionMapping.del(id)
|
||||||
discard await subscriptions.client.eth_uninstallFilter(sub)
|
discard await subscriptions.client.eth_uninstallFilter(sub)
|
||||||
except CancelledError as e:
|
except CancelledError as e:
|
||||||
raise e
|
raise e
|
||||||
except CatchableError:
|
except KeyError, CatchableError:
|
||||||
# Ignore if uninstallation of the filter fails. If it's the last step in our
|
# Ignore if uninstallation of the filter fails. If it's the last step in our
|
||||||
# cleanup, then filter changes for this filter will no longer be polled so
|
# cleanup, then filter changes for this filter will no longer be polled so
|
||||||
# if the filter continues to live on in geth for whatever reason then it
|
# if the filter continues to live on in geth for whatever reason then it
|
||||||
|
|
Loading…
Reference in New Issue