powersync.dart icon indicating copy to clipboard operation
powersync.dart copied to clipboard

ClosedException after stopSyncing() called.

Open abjox opened this issue 1 month ago • 2 comments

powersync_core: ^1.6.1 powersync_sqlcipher: ^0.1.13

Image
flutter: PowerSync: INFO: AttachmentQueue closed.
flutter: AppConfiguration: Uncaught app exception: ClosedException
flutter: #0      SqliteConnectionPool.readLock (package:sqlite_async/src/native/database/connection_pool.dart:132:7)
connection_pool.dart:132
#1      SqliteDatabaseImpl.readLock (package:sqlite_async/src/native/database/native_sqlite_database.dart:150:18)
native_sqlite_database.dart:150
#2      PowerSyncDatabaseImpl.readLock (package:powersync_core/src/database/native/native_powersync_database.dart:292:21)
native_powersync_database.dart:292
<asynchronous suspension>
#3      AttachmentContext.getAttachments (package:powersync_core/src/attachments/implementations/attachment_context.dart:79:21)
attachment_context.dart:79
<asynchronous suspension>
#4      AttachmentQueue._processWatchedAttachments.<anonymous closure> (package:powersync_core/src/attachments/attachment_queue_service.dart:250:34)
attachment_queue_service.dart:250
<asynchronous suspension>
#5      AttachmentService.withContext.<anonymous closure> (package:powersync_core/src/attachments/implementations/attachment_service.dart:68:16)
attachment_service.dart:68
<asynchronous suspension>
#6      SimpleMutex.lock.<anonymous closure> (package:sqlite_async/src/native/native_isolate_mutex.dart:65:16)
native_isolate_mutex.dart:65
<asynchronous suspension><…>

abjox avatar Nov 06 '25 07:11 abjox

I assume you've also closed the database immediately after calling stopSyncing(). Did you await the stopSyncing() call before doing that?

simolus3 avatar Nov 06 '25 08:11 simolus3

Hi @simolus3

Yes — I close the database and delete local data on logout. Before doing that, stopSyncing() is awaited. The root cause appears to be that the _watchAttachments listener is not being cancelled on the powersync_core side. Because of that, _processWatchedAttachments is still triggered once more after logout. As a temporary workaround I explicitly cancel watching attachment updates on my side so _processWatchedAttachments does not run again.

abjox avatar Nov 06 '25 08:11 abjox