codex-storage / nim-ethers

Port of ethers.js to Nim
Other
8 stars 4 forks source link

eth_getFilterChanges occasionally returns JNull on Windows #79

Closed marcinczenko closed 1 month ago

marcinczenko commented 1 month ago

On Windows when running tests, occasionally tests were failing with the following error:

`node.kind == JArray` : items() can not iterate a JsonNode of kind JNull"

the error is caused by eth_getFilterChanges occasionally returning JNull instead of JArray on Windows.

This is happening in vendor/nim-ethers/ethers/providers/jsonrpc/subscriptions.nim:

proc getChanges(id: JsonNode): Future[JsonNode] {.async.} =
  try:
    return await subscriptions.client.eth_getFilterChanges(id)
  except CatchableError:
    return newJArray()

proc poll(id: JsonNode) {.async.} =
  for change in await getChanges(id):
    if callback =? subscriptions.getCallback(id):
      callback(id, change)

The code is basically correct, as should always return a JArray. A fix could e.g.:

proc poll(id: JsonNode) {.async.} =
  let changes = await getChanges(id)
  if changes.kind != JArray:
    return
  for change in changes:
    if callback =? subscriptions.getCallback(id):
      callback(id, change)

Alternatively, we could also modify the getChanges proc.

A similar issue were reported in the past for go-ethereum: https://github.com/ethereum/go-ethereum/issues/2746, but it should be resolved by now. Maybe somehow it propagated to HardHat and apparently on Windows only - I could not find any issue at Hardhat's GitHub.