hyperledger / aries-askar

Secure storage designed for Hyperledger Aries agents.
Apache License 2.0
59 stars 45 forks source link

AskarWallet.close: Invalid resource handle #182

Open niall-shaw opened 12 months ago

niall-shaw commented 12 months ago

We have a node project that is running test suites via jest. In two of the suites, we are using AFJ to test mediation cases. All AFJ agents are using Askar, and mediator agents are using postgres storage.

On MacOS, the tests are consistently working fine without any failures, but on Linux (Ubuntu 20.04) some test suites are failing to start due to Askar closing errors:

WalletError: Error closing wallet': Resource handle in use
      at AskarWallet.close (node_modules/@aries-framework/askar/src/wallet/AskarWallet.ts:383:13)
      at WalletApi.close (node_modules/@aries-framework/core/src/wallet/WalletApi.ts:97:5)
      at Agent.shutdown (node_modules/@aries-framework/core/src/agent/Agent.ts:218:7)

and

ERROR: Error closing wallet': Invalid resource handle {
        "error": {
          "name": "Error",
          "stack": "Error: Invalid resource handle\n    at NodeJSAriesAskar.handleError (/app/node_modules/@hyperledger/aries-askar-nodejs/src/NodeJSAriesAskar.ts:200:11)\n    at cb (/app/node_modules/@hyperledger/aries-askar-nodejs/src/NodeJSAriesAskar.ts:144:16)\n    at Object.<anonymous> (/app/node_modules/ffi-napi/lib/callback.js:66:27)\n    at Object.callbackTrampoline (node:internal/async_hooks:130:17)",
          "message": "Invalid resource handle",
          "code": 5
        },
        "errorMessage": "Invalid resource handle"
      }

Note, this is only happening on Linux (via Github Actions), and is not happening ALL of the time. Just most of the time.

Update: We use Node v18.16.0

TimoGlastra commented 12 months ago

I've seen this happen sometimes when we try close the wallet and afterwards still try to process an incoming message / use the wallet, even though it was already closed.

andrewwhitehead commented 12 months ago

I think this must be isolated to the JS wrapper, passing in a Store handle after it has been removed.

niall-shaw commented 11 months ago

Any idea how to fix this @TimoGlastra ? Our CI fails most of the time due to this

TimoGlastra commented 11 months ago

Could you provide maybe a repo with a minimal reproduction? That would really help in debugging the issue.

However, as this is happening on Github Actions (which is like really slow), I think it's just a race condition in your tests, and maybe not a problem on macOS as your local machine is a lot faster.

Is your agent processing any messages? Could it be that something is not fully awaited before closing the agent?

E.g. an issue I've run in quite often with AFJ is that it would keep picking up messages, and so then we'd close the wallet and it would still receive pickup messages, and thus cause issues. The solution was to first stop messages pickup, so the agent was for sure not processing anything anymore, and then closing it.

GHkrishna commented 7 months ago

Hello @niall-shaw, Any updates on the issue and if you were able to solve it?