Skip to content

fix(shared-internals): clear disconnectingPromise after a failed disconnect - #1098

Open
cpruijsen wants to merge 1 commit into
powersync-ja:mainfrom
cpruijsen:fix/issue-1097
Open

fix(shared-internals): clear disconnectingPromise after a failed disconnect#1098
cpruijsen wants to merge 1 commit into
powersync-ja:mainfrom
cpruijsen:fix/issue-1097

Conversation

@cpruijsen

Copy link
Copy Markdown

Summary

disconnectInternal() clears disconnectingPromise in a finally so a rejected disconnect() no longer leaves ConnectionManager unable to disconnect or connect again. The next call starts a new teardown instead of returning the same cached rejection (#1097). Concurrent in-flight disconnect() calls still share one promise and the same rejection; only a later call retries.

disconnectInternal() is also on the connect() path, and disconnectAndClear() disconnects first, so one teardown failure previously blocked reconnect and clear for the life of the instance.

try/finally wraps the existing await of disconnectingPromise, matching ControlledExecutor.execute() in this package (clear the in-flight field in finally whether the task fulfills or rejects). The try/finally form is the patch specified and verified in #1097. An alternative is this.disconnectingPromise = this.performDisconnect().finally(() => { this.disconnectingPromise = null }).

performDisconnect() is unchanged: it still does not dispose() after disconnect() throws. Members are already nulled before those awaits, so a retry is a no-op rather than a double-dispose.

Test plan

  • pnpm exec vitest run tests/client/ConnectionManager.test.ts in packages/shared-internals. New tests fail without the finally, pass with it
  • pnpm exec vitest run in packages/shared-internals (59 tests)
  • Changeset included for @powersync/shared-internals (patch)

Closes #1097

…onnect

A rejected performDisconnect() previously left the latch set, so every later disconnect() and connect() failed with the same cached error.
@changeset-bot

changeset-bot Bot commented Sep 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a1c2a7f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@powersync/shared-internals Patch
@powersync/adapter-sql-js Patch
@powersync/capacitor Patch
@powersync/node Patch
@powersync/react-native Patch
@powersync/web Patch
@powersync/diagnostics-app Patch

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant