Skip to content

Conversation

Chriztiaan
Copy link
Contributor

@Chriztiaan Chriztiaan commented Mar 26, 2025

In some cases for web with multiple tabs support enabled, multiple 'connect()` calls in a single tab happening in succession can cause a navigator lock to be stuck in an unreleased state. This blocks the sync worker from getting a connection and syncing/connecting breaks.

Two typical scenarios that can cause this is switching client parameters and React's StrictMode which does multiple calls of hooks like useEffect.

Cherrypicked commit from @stevensJourney.

Copy link

changeset-bot bot commented Mar 26, 2025

🦋 Changeset detected

Latest commit: a54a914

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

This PR includes changesets to release 2 packages
Name Type
@powersync/web Minor
@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

@Chriztiaan Chriztiaan marked this pull request as ready for review March 26, 2025 10:43
@Chriztiaan Chriztiaan requested a review from simolus3 March 26, 2025 10:43
}

// Clearing the adapter will result in a new one being opened in connect
await trackedPort.clientProvider.releaseSharedConnection();
Copy link
Contributor

Choose a reason for hiding this comment

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

For my own understanding: Where would we release the lock otherwise? Through trackedPort.db.close()?

I don't have a good mental model of how we're sharing connections here, but I'm worried about whether it's possible for us to release the shared connection here and someone else then re-obtaining the lock on a different connection? (so we'd have two of them when it sounds like we probably only want to have one).

If the lock is only held to avoid the tab being put to sleep as the comment suggests, why aren't we just requesting a randomly-named lock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the lock is only held to avoid the tab being put to sleep as the comment suggests, why aren't we just requesting a randomly-named lock?

You are the second person to suggest this. I think you're spot on here.

@Chriztiaan
Copy link
Contributor Author

Closed in favour of #546

@Chriztiaan Chriztiaan closed this Mar 26, 2025
@Chriztiaan Chriztiaan deleted the fix/nav-lock-double-connect branch April 9, 2025 09:13
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.

3 participants