do not crash polling when just unsubscribed

This commit is contained in:
Mark Spanbroek 2024-11-12 08:44:51 +01:00 committed by markspanbroek
parent c6a59b5187
commit f15d55f513
2 changed files with 18 additions and 19 deletions

View File

@ -171,13 +171,11 @@ proc new*(_: type JsonRpcSubscriptions,
discard discard
proc getChanges(id: JsonNode): Future[JsonNode] {.async: (raises: [CancelledError]).} = proc getChanges(id: JsonNode): Future[JsonNode] {.async: (raises: [CancelledError]).} =
if mappedId =? subscriptions.subscriptionMapping.?[id]:
try: try:
let mappedId = subscriptions.subscriptionMapping[id]
let changes = await subscriptions.client.eth_getFilterChanges(mappedId) let changes = await subscriptions.client.eth_getFilterChanges(mappedId)
if changes.kind == JArray: if changes.kind == JArray:
return changes return changes
except KeyError as error:
raiseAssert "subscription mapping invalid: " & error.msg
except JsonRpcError: except JsonRpcError:
await resubscribe(id) await resubscribe(id)
# TODO: we could still miss some events between losing the subscription # TODO: we could still miss some events between losing the subscription

View File

@ -1,3 +1,4 @@
-d:"chronicles_log_level=INFO" -d:"chronicles_log_level=INFO"
-d:"json_rpc_websocket_package=websock" -d:"json_rpc_websocket_package=websock"
--warning[LockLevel]:off --warning[LockLevel]:off
--warning[DotLikeOps]:off