-
Notifications
You must be signed in to change notification settings - Fork 61
[Fix] OPFS Multitab Deadlocks #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
base: main
Are you sure you want to change the base?
Changes from all commits
e61059a
a12145f
b4f5c1b
355e396
c6ba9f6
9730337
58f412b
8721538
feca863
b0dd596
de7804f
c08e664
aedc855
62b04de
0fc0d73
91db686
deaf83c
3780223
8f95e10
1e880d6
da53396
28472e3
11b7a36
7e7ec91
1e9fa3f
07231cb
cbfb683
f881992
ffe5abe
58d9194
1ef44a3
d73d9d2
a1fd0bb
445ec69
6630097
bbfdcf7
8cfc0e6
abdec98
9cadf24
4a12be8
eb88fde
423e4e4
59b9ce9
23ae289
4108c8e
cf14827
0f1cb7c
9a571f1
33f701e
093312e
c72c2dd
cac6202
977b2a0
b48a685
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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. |
| 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. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { CoreStreamSubscription } from '../../client/sync/stream/core-instruction.js'; | ||
| import { SyncClientImplementation } from '../../client/sync/stream/AbstractStreamingSyncImplementation.js'; | ||
| import { InternalProgressInformation, ProgressWithOperations, SyncProgress } from './SyncProgress.js'; | ||
| import { CoreStreamSubscription } from '../../client/sync/stream/core-instruction.js'; | ||
| import { SyncStreamDescription, SyncSubscriptionDescription } from '../../client/sync/sync-streams.js'; | ||
| import { InternalProgressInformation, ProgressWithOperations, SyncProgress } from './SyncProgress.js'; | ||
|
|
||
| export type SyncDataFlowStatus = Partial<{ | ||
| downloading: boolean; | ||
|
|
@@ -250,13 +250,28 @@ export class SyncStatus { | |
| return { | ||
| connected: this.connected, | ||
| connecting: this.connecting, | ||
| dataFlow: this.dataFlowStatus, | ||
| dataFlow: { | ||
| ...this.dataFlowStatus, | ||
| uploadError: this.serializeError(this.dataFlowStatus.uploadError), | ||
| downloadError: this.serializeError(this.dataFlowStatus.downloadError) | ||
| }, | ||
| lastSyncedAt: this.lastSyncedAt, | ||
| hasSynced: this.hasSynced, | ||
| priorityStatusEntries: this.priorityStatusEntries | ||
| }; | ||
| } | ||
|
|
||
| protected serializeError(error?: Error) { | ||
|
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. Not all errors are serialisable over a MessagePort. E.g. some
Contributor
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. Would perhaps be nice to mention that as a reason in a comment on this method or on line 255 where it's used. |
||
| if (typeof error == 'undefined') { | ||
| return undefined; | ||
| } | ||
| return { | ||
| name: error.name, | ||
| message: error.message, | ||
| stack: error.stack | ||
| }; | ||
| } | ||
|
|
||
| private static comparePriorities(a: SyncPriorityStatus, b: SyncPriorityStatus) { | ||
| return b.priority - a.priority; // Reverse because higher priorities have lower numbers | ||
| } | ||
|
|
||
| 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 | ||
| }); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,18 @@ export type ProxiedQueryResult = Omit<QueryResult, 'rows'> & { | |
| */ | ||
| export type OnTableChangeCallback = (event: BatchedUpdateNotification) => void; | ||
|
|
||
| /** | ||
| * Thrown when an underlying database connection is closed. | ||
| * This is particularly relevant when worker connections are marked as closed while | ||
| * operations are still in progress. | ||
| */ | ||
| export class ConnectionClosedError extends Error { | ||
|
Contributor
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. nit: We could consider moving and exporting this from |
||
| constructor(message: string) { | ||
| super(message); | ||
| this.name = 'ConnectionClosedError'; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * @internal | ||
| * An async Database connection which provides basic async SQL methods. | ||
|
|
||
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.
Do we want to check this in or have a commented out example?
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.
I think it would be nice to have an example/demo of OPFS being used.