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

refactor(askar)!: short-lived askar sessions #1743

Conversation

TimoGlastra
Copy link
Contributor

This should address some issues we've encountered with Askar where if a long-lived session dies the wallet is not usable anymore.

With askar, sessions are meant to be short-lived and then askar can manage a pool of connections.

This will also improve cases where a lot of tenant sessions are opened at the same time which could result in deadlocks as we had to keep a session open for each open tenant, while now we close the tenant session, even if the tenant agentContext is still open. In a future PR I'll probalby do some rework on the session mutex stuff as that becomes a lot less useful as opening a new tenant is as simple as opening a profile, so there's not really overhead in having a lot of sessions open unless DatabasePerWallet is used in multi-tenancy

In the future we can also start batching multiple reads/writes so that if it fails we can rollback and we won't have partially updated state (think adding CredentilaExchangeRecord + DidCommMessageRecord). but that is probably something for 0.6 as we need to revamp the Wallet / Session api for that. This is now just internally to askar.

Some breaking changes related to export/import as described here: hyperledger/aries-askar#221

Copy link
Contributor

@genaris genaris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great addition and solved in a very elegant way!

try {
if (recipientKeyEntry) {
return didcommV1Unpack(messagePackage, recipientKeyEntry.key)
// TODO: how long should sessions last? Just for the duration of the unpack? Or should each item in the recipientKids get a separate session?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know what's exactly the overhead of getting references to sessions in the pool (probably not much/nearly zero) but in this case I think it will become clearer if a single session is used for the whole unpack process (especially once we switch to the using keyword).

forUpdate: false,
isJson: false,
// TODO: what is faster? listProfiles or open and close session?
// I think open/close is more scalable (what if profiles is 10.000.000?)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be an interesting stress test! Currently, list_profiles makes a single query (SELECT name FROM profiles) and returns all strings at once to FFI layer. In case of millions of records I guess there can be problems in different parts of the stack being used (e.g. maximum variable/array size, SQL query/response length, etc.).

So I think unless there is a new method in askar allowing to check if a particular profile exists, it is safer to do the open/close

this.walletConfig = walletConfig
this._session = await this._store.openSession()
} catch (error) {
// FIXME: Askar should throw a Duplicate error code, but is currently returning Encryption
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, do you know if this is still happening? There were quite a good number of fixes regarding this in Askar in the past months.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No not sure, but we can find out :)

@TimoGlastra TimoGlastra force-pushed the feat/short-lived-askar-sessions branch from 175ca30 to ed14a57 Compare February 7, 2024 08:56
@TimoGlastra TimoGlastra merged commit 2cb9ba8 into openwallet-foundation:main Feb 7, 2024
7 checks passed
@TimoGlastra TimoGlastra deleted the feat/short-lived-askar-sessions branch February 7, 2024 09:53
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

Successfully merging this pull request may close these issues.

2 participants