Repository navigation
fix(shared-internals): clear ConnectionManager's init and disconnect promises when they reject - #1177
Open
shahjahangc wants to merge 1 commit into
Open
shahjahangc wants to merge 1 commit into
shahjahangc wants to merge 1 commit into
Conversation
…promises when they reject connectInternal() kept a rejected syncStreamInitPromise, which performDisconnect() awaits first, so one failed sync implementation creation made every later disconnect(), and the next connect(), reject with that error. disconnectInternal() likewise kept a rejected disconnectingPromise and handed it to every later caller; a disconnect waiting on a creation that fails reaches it even with the first fix. Both are now cleared in a finally. Fixes powersync-ja#1097 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 7fa7831 The changes in this PR will be included in the next version bump. This PR includes changesets to release 7 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
simolus3
approved these changes
Oct 27, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #1097
Two of
ConnectionManager's in-flight promise fields,syncStreamInitPromiseanddisconnectingPromise, were cleared only when the promise resolved.connectInternal()stores the sync implementation's creation insyncStreamInitPromise. When the creation rejects, the field keeps the rejected promise, andperformDisconnect()awaits that field first. So after one failed creation, every laterdisconnect()rejects with the creation's error, and so does the nextconnect(), which disconnects first. Theconnect()whose creation failed still resolves.disconnectInternal()stores the in-flight disconnect indisconnectingPromise, and a rejected one stays there for every later caller. The first fix does not close this: adisconnect()that is waiting on a creation when the creation fails rejects too, and its promise is kept here.Both fields are now cleared in a
finally, as discussed in #1097. Adisconnect()already waiting on either promise still gets its rejection; the next call starts over.I left the async promise executor as it is to keep this to the fix. Happy to swap it for an async lambda here or separately.
Tests. Three cases in
tests/client/ConnectionManager.test.ts, on the existing harness:disconnect()resolves, and a reconnect creates and connects a new implementation. Onmain, thatdisconnect()rejects with the creation's error.disconnect()that is waiting on a creation that fails still rejects with that error, and the nextdisconnect()resolves. Onmain, the next one rejects with the same error.disconnect()whosesync.disconnect()rejects, the nextdisconnect()resolves and a reconnect works. Onmain, the next one rejects with the same error.Reverting
connectInternal()'sfinallyturns the first two red, and revertingdisconnectInternal()'s turns the last two red. All 79shared-internalstests pass,tsc --noEmitis clean for the package'ssrc(its tsconfig does not includetests/), and the changed files are formatted with the repo's prettier settings. There's a patch changeset.Left out, found while testing. All three exist on
main. With this change the manager keeps working after a failure, so they can now happen more than once:sync.disconnect()throws,performDisconnect()never callsdispose()or the disposer, so that implementation is not disposed.BasePowerSyncDatabase'screateSyncImplementationbuilds the sync and then awaits itswaitForReady(). If that rejects, the sync is dropped without being disposed.connect()swallows a failed creation and nothing logs it. Onmain, the nextdisconnect()orconnect()happened to surface the error by rejecting with it; with this change nothing does.Happy to take any of these here or in a follow-up.
🤖 Generated with Claude Code