mirror of
https://github.com/status-im/nim-ethers.git
synced 2025-02-04 19:44:13 +00:00
makes sure that a key on subscriptionMapping exists before trying to access it
This commit is contained in:
parent
d88e4614b1
commit
4642545309
@ -285,15 +285,16 @@ method unsubscribe*(subscriptions: PollingSubscriptions,
|
||||
{.async.} =
|
||||
subscriptions.logFilters.del(id)
|
||||
subscriptions.callbacks.del(id)
|
||||
let sub = subscriptions.subscriptionMapping[id]
|
||||
subscriptions.subscriptionMapping.del(id)
|
||||
try:
|
||||
discard await subscriptions.client.eth_uninstallFilter(sub)
|
||||
except CancelledError as e:
|
||||
raise e
|
||||
except CatchableError:
|
||||
# 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
|
||||
# if the filter continues to live on in geth for whatever reason then it
|
||||
# doesn't matter.
|
||||
discard
|
||||
if subscriptions.subscriptionMapping.hasKey(id):
|
||||
let sub = subscriptions.subscriptionMapping[id]
|
||||
subscriptions.subscriptionMapping.del(id)
|
||||
try:
|
||||
discard await subscriptions.client.eth_uninstallFilter(sub)
|
||||
except CancelledError as e:
|
||||
raise e
|
||||
except CatchableError:
|
||||
# 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
|
||||
# if the filter continues to live on in geth for whatever reason then it
|
||||
# doesn't matter.
|
||||
discard
|
||||
|
@ -49,6 +49,15 @@ template subscriptionTests(subscriptions, client) =
|
||||
discard await client.call("evm_mine", newJArray())
|
||||
await sleepAsync(100.millis)
|
||||
check count == 0
|
||||
|
||||
test "unsubscribing from a non-existent subscription does not do any harm":
|
||||
await subscriptions.unsubscribe(newJInt(0))
|
||||
|
||||
test "duplicate unsubscribe is harmless":
|
||||
proc callback(blck: Block) = discard
|
||||
let subscription = await subscriptions.subscribeBlocks(callback)
|
||||
await subscriptions.unsubscribe(subscription)
|
||||
await subscriptions.unsubscribe(subscription)
|
||||
|
||||
test "stops listening to new blocks when provider is closed":
|
||||
var count = 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user