Allow disconnecting in fetchCredentials
callback
#279
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
To prevent duplicate concurrent sync connections, we guard
connect()
anddisconnect()
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 callingconnect()
which is then used to run callbacks.This allows calling
disconnect()
in response to tokens expiring andfetchCredentials
being called (as long as that call is not awaited -disconnect()
will await the abortion which is then blocked on thedisconnect()
call itself).Closes #278.