Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AskarWallet.close: Invalid resource handle #182

Open
niall-shaw opened this issue Sep 20, 2023 · 5 comments
Open

AskarWallet.close: Invalid resource handle #182

niall-shaw opened this issue Sep 20, 2023 · 5 comments

Comments

@niall-shaw
Copy link

niall-shaw commented Sep 20, 2023

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
Copy link
Member

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
Copy link
Member

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

@niall-shaw
Copy link
Author

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

@TimoGlastra
Copy link
Member

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants