Skip to content

Allow disconnecting in fetchCredentials callback #279

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

Merged
merged 2 commits into from
May 14, 2025

Conversation

simolus3
Copy link
Contributor

To prevent duplicate concurrent sync connections, we guard connect() and disconnect() calls in mutexes. And since the mutex implementation is not reentrant, there's a check ensuring another call to .lock() throws if it comes from an async zone that already holds the mutex.

By design, async zones are quite sticky: Every callback we register in that zone will also run in the same zone. So when we call connectInternal on the native database, all message handlers from the isolate are handled in the zone originally establishing the connection.

This means that these callbacks can't call disconnect(), which is unfortunate because the lock is not actually held at that point. This fixes that issue by passing the zone originally calling connect() which is then used to run callbacks.
This allows calling disconnect() in response to tokens expiring and fetchCredentials being called (as long as that call is not awaited - disconnect() will await the abortion which is then blocked on the disconnect() call itself).

Closes #278.

@simolus3 simolus3 requested a review from rkistner May 14, 2025 09:52
@simolus3 simolus3 merged commit f5de535 into main May 14, 2025
5 checks passed
@simolus3 simolus3 deleted the test-disconnect-while-fetching-credentials branch May 14, 2025 10:11
@simolus3 simolus3 mentioned this pull request May 29, 2025
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.

Disconnect while connecting (fetching credentials)
2 participants