-
Notifications
You must be signed in to change notification settings - Fork 60
[Fix] OPFS Multitab issue #786
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
Draft
Chriztiaan
wants to merge
47
commits into
main
Choose a base branch
from
fix/opfs-multitab-issue
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
e61059a
No longer awaiting when aborting connection on tab closure. Fixes som…
Chriztiaan a12145f
fix opfs deadlocks
stevensJourney b4f5c1b
Add multiple tabs test
stevensJourney 355e396
enable headless
stevensJourney c6ba9f6
reenable browsers
stevensJourney 9730337
cleanup tests
stevensJourney 58f412b
Merge branch 'dead-tab-detection' into fix/opfs-multitab-issue
stevensJourney 8721538
Add default lock timeout for shared sync workers. Add flagging for u…
stevensJourney feca863
fix broken test
stevensJourney b0dd596
cleanup tests
stevensJourney de7804f
restore collectActiveSubscriptions
stevensJourney c08e664
cleanup code flow
stevensJourney aedc855
Add withTimeout for opening db connections
stevensJourney 62b04de
reduce number of iframes for CI
stevensJourney 0fc0d73
Use a distributed database adapter instead of reconnecting. Retry ope…
stevensJourney 91db686
Catch closed errors for hold requests. Use crud throttle time for cru…
stevensJourney deaf83c
Synchronize lock requests better.
stevensJourney 3780223
Re-open database as soon as it's closed. Trigger uploads if database …
stevensJourney 8f95e10
Update tabs test to be more indicative of the actual issues.
stevensJourney 1e880d6
Add mocked sync tests for shared webworkers
stevensJourney da53396
Update tests for shared web workers
stevensJourney 28472e3
Add automatic responses or mocked sync service.
stevensJourney 11b7a36
Update more tests to use mocked sync service
stevensJourney 7e7ec91
increase timeout for ci
stevensJourney 1e9fa3f
Improve test stability
stevensJourney 07231cb
cleanup port assignments and init flow
stevensJourney cbfb683
cleanup test code
stevensJourney f881992
Listen for database close events to catch closed items earlier.
stevensJourney ffe5abe
Fire and forget close operations.
stevensJourney 58d9194
Common changeset.
Chriztiaan 1ef44a3
Try and catch Accesshandle errors. Fork OPFSCoopSyncVFS for potential…
stevensJourney d73d9d2
Cleanup aborted operations if aborted. Try and gracefully handle Acce…
stevensJourney a1fd0bb
cleanup
stevensJourney 445ec69
add a finalization registry entry to release access handles
stevensJourney 6630097
Wrap entire open operation init in writeLock.
stevensJourney bbfdcf7
revert opfs test
stevensJourney 8cfc0e6
update wa-sqlite
stevensJourney abdec98
Update changesets
stevensJourney 9cadf24
try stabilize test
stevensJourney 4a12be8
increase timeouts
stevensJourney eb88fde
cleanup any opened access handles if an error is caught.
stevensJourney 423e4e4
cleanup tests structure
stevensJourney 59b9ce9
remove dev logs
stevensJourney 23ae289
fix types
stevensJourney 4108c8e
Changesets for Drizzle/Kysely.
Chriztiaan cf14827
use latest dev packages
stevensJourney 0f1cb7c
Code cleanup. make minor bump.
stevensJourney File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| '@powersync/web': minor | ||
| --- | ||
|
|
||
| - Fixed some edge cases where multiple tabs with OPFS can cause sync deadlocks. | ||
| - Fixed issue where calling `powerSync.close()` would cause a disconnect if using multiple tabs (the default should not be to disconnect if using multiple tabs) | ||
| - Improved shared sync implementation database delegation and opening strategy. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@powersync/drizzle-driver': patch | ||
| '@powersync/kysely-driver': patch | ||
| --- | ||
|
|
||
| Updating `wa-sqlite` to ^1.3.4. |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@powersync/common': minor | ||
| --- | ||
|
|
||
| - Improved serializing of upload and download errors for SyncStatus events. Some JS `Error`s are not cloneable, the JSON representation of a SyncStatus should now always be cloneable. |
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,32 +1,31 @@ | ||
| import { | ||
| type BucketStorageAdapter, | ||
| type PowerSyncBackendConnector, | ||
| type PowerSyncCloseOptions, | ||
| type RequiredAdditionalConnectionOptions, | ||
| AbstractPowerSyncDatabase, | ||
| DBAdapter, | ||
| DEFAULT_POWERSYNC_CLOSE_OPTIONS, | ||
| isDBAdapter, | ||
| isSQLOpenFactory, | ||
| PowerSyncDatabaseOptions, | ||
| PowerSyncDatabaseOptionsWithDBAdapter, | ||
| PowerSyncDatabaseOptionsWithOpenFactory, | ||
| PowerSyncDatabaseOptionsWithSettings, | ||
| SqliteBucketStorage, | ||
| StreamingSyncImplementation | ||
| StreamingSyncImplementation, | ||
| isDBAdapter, | ||
| isSQLOpenFactory, | ||
| type BucketStorageAdapter, | ||
| type PowerSyncBackendConnector, | ||
| type PowerSyncCloseOptions, | ||
| type RequiredAdditionalConnectionOptions | ||
| } from '@powersync/common'; | ||
| import { Mutex } from 'async-mutex'; | ||
| import { getNavigatorLocks } from '../shared/navigator'; | ||
| import { WebDBAdapter } from './adapters/WebDBAdapter'; | ||
| import { WASQLiteOpenFactory } from './adapters/wa-sqlite/WASQLiteOpenFactory'; | ||
| import { | ||
| DEFAULT_WEB_SQL_FLAGS, | ||
| ResolvedWebSQLOpenOptions, | ||
| resolveWebSQLFlags, | ||
| WebSQLFlags | ||
| WebSQLFlags, | ||
| resolveWebSQLFlags | ||
| } from './adapters/web-sql-flags'; | ||
| import { WebDBAdapter } from './adapters/WebDBAdapter'; | ||
| import { SharedWebStreamingSyncImplementation } from './sync/SharedWebStreamingSyncImplementation'; | ||
| import { SSRStreamingSyncImplementation } from './sync/SSRWebStreamingSyncImplementation'; | ||
| import { SharedWebStreamingSyncImplementation } from './sync/SharedWebStreamingSyncImplementation'; | ||
| import { WebRemote } from './sync/WebRemote'; | ||
| import { | ||
| WebStreamingSyncImplementation, | ||
|
|
@@ -160,14 +159,13 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase { | |
| * By default the sync stream client is only disconnected if | ||
| * multiple tabs are not enabled. | ||
| */ | ||
| close(options: PowerSyncCloseOptions = DEFAULT_POWERSYNC_CLOSE_OPTIONS): Promise<void> { | ||
| close(options?: PowerSyncCloseOptions): Promise<void> { | ||
| if (this.unloadListener) { | ||
| window.removeEventListener('unload', this.unloadListener); | ||
| } | ||
|
|
||
| return super.close({ | ||
| // Don't disconnect by default if multiple tabs are enabled | ||
| disconnect: options.disconnect ?? !this.resolvedFlags.enableMultiTabs | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default param above actually causes the opposite of this to occur. A |
||
| disconnect: options?.disconnect ?? !this.resolvedFlags.enableMultiTabs | ||
| }); | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all errors are serialisable over a MessagePort. E.g. some
DomExceptions fail to be passed across workers. This explicitly serialises errors in theSyncStatusnow.