Skip to content

Commit a722156

Browse files
committed
Fix "Concurrent modification during iteration" errors.
1 parent 8417334 commit a722156

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/src/connection_pool.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,12 @@ class SqliteConnectionPool with SqliteQueries implements SqliteConnection {
183183
@override
184184
Future<void> close() async {
185185
closed = true;
186-
for (var connection in _readConnections) {
186+
187+
// It is possible that `readLock()` removes connections from the pool while we're
188+
// closing connections, but not possible for new connections to be added.
189+
// Create a copy of the list, to avoid this triggering "Concurrent modification during iteration"
190+
final toClose = _readConnections.sublist(0);
191+
for (var connection in toClose) {
187192
await connection.close();
188193
}
189194
// Closing the write connection cleans up the journal files (-shm and -wal files).

test/basic_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,6 @@ void main() {
383383
// Second connection to sleep more than first connection
384384
'SELECT test_sleep(test_connection_number() * 10)'
385385
]));
386-
await createTables(db);
387386

388387
final future1 = db.get('SELECT test_sleep(10) as sleep');
389388
final future2 = db.get('SELECT test_sleep(10) as sleep');

0 commit comments

Comments
 (0)