File tree Expand file tree Collapse file tree 3 files changed +8
-1
lines changed
Expand file tree Collapse file tree 3 files changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -54,6 +54,7 @@ export class WASQLiteDBAdapter extends LockedAsyncDatabaseAdapter {
5454 const remote = Comlink . wrap < OpenAsyncDatabaseConnection > ( workerPort ) ;
5555 return new WorkerWrappedAsyncDatabaseConnection ( {
5656 remote,
57+ remoteCanCloseUnexpectedly : false ,
5758 identifier : options . dbFilename ,
5859 baseConnection : await remote ( {
5960 ...options ,
Original file line number Diff line number Diff line change @@ -82,6 +82,8 @@ export class WASQLiteOpenFactory extends AbstractWebSQLOpenFactory {
8282
8383 return new WorkerWrappedAsyncDatabaseConnection ( {
8484 remote : workerDBOpener ,
85+ // This tab owns the worker, so we're guaranteed to outlive it.
86+ remoteCanCloseUnexpectedly : false ,
8587 baseConnection : await workerDBOpener ( {
8688 dbFilename : this . options . dbFilename ,
8789 vfs,
Original file line number Diff line number Diff line change @@ -481,9 +481,13 @@ export class SharedSyncImplementation extends BaseObserver<SharedSyncImplementat
481481 const wrapped = new WorkerWrappedAsyncDatabaseConnection ( {
482482 remote,
483483 baseConnection : db ,
484- identifier
484+ identifier,
485+ // It's possible for this worker to outlive the client hosting the database for us. We need to be prepared for
486+ // that and ensure pending requests are aborted when the tab is closed.
487+ remoteCanCloseUnexpectedly : true
485488 } ) ;
486489 lastClient . closeListeners . push ( ( ) => {
490+ this . logger . info ( 'Aborting open connection because associated tab closed.' ) ;
487491 wrapped . markRemoteClosed ( ) ;
488492 } ) ;
489493
You can’t perform that action at this time.
0 commit comments