Commit 3fb6a7b
authored
Problems :
Closing the database with an active MultipeerReplicator running failed with the timeout error. Three related issues contributed to this bug:
1. Incorrect CountDownLatch reset in AbstractDatabase.shutdown() : When close() returns a BUSY error, the latch was reset to 2 under the assumption that a new process would be found in verifyActiveProcesses(). This assumption is not always valid (e.g. a background thread is still accessing the database during close). As a result, the latch never reaches zero and close() is never retried correctly.
2. MultipeerReplicator.onSyncStatusChanged reports inactive early (fixed in EE repo) : MultipeerReplicator.onSyncStatusChanged marked the process offline immediately but deferred unregisterProcess to an async callback . As a result, AbstractDatabase could treat the process as stopped, attempt to close the database too early, and receive BUSY from LiteCore. (fixed in EE repo)
3. Deadlock when close() is called from the Android main thread (fixed in EE repo) : Waiting for all active processes to unregister blocks the main thread, while shutdownConflictResolverService is also scheduled on the main thread (default executor), causing a deadlock.
Fixes
Simplified the shutdown logic by splitting it into two independent phases, which also eliminates the problematic CountDownLatch reset:
Phase 1 — Drain active processes: Shut down all active processes, then wait for them to finish or time out (10 secs).
Phase 2 — Close the database: Attempt close(); if BUSY is returned, wait briefly (2 secs) and retry (max 5 retries).
Previously, the two phases were interleaved in a single loop: shut down processes → wait → close → on BUSY, reset latch to 2 and repeat from the top (max 5 retries). This coupling was the root cause of the latch never reaching zero.
1 parent 8ae6fd2 commit 3fb6a7b
1 file changed
Lines changed: 21 additions & 26 deletions
Lines changed: 21 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
95 | | - | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
96 | 101 | | |
97 | 102 | | |
98 | 103 | | |
| |||
1224 | 1229 | | |
1225 | 1230 | | |
1226 | 1231 | | |
1227 | | - | |
1228 | 1232 | | |
1229 | 1233 | | |
1230 | 1234 | | |
| |||
1251 | 1255 | | |
1252 | 1256 | | |
1253 | 1257 | | |
1254 | | - | |
1255 | | - | |
| 1258 | + | |
| 1259 | + | |
| 1260 | + | |
| 1261 | + | |
1256 | 1262 | | |
1257 | | - | |
1258 | | - | |
| 1263 | + | |
| 1264 | + | |
| 1265 | + | |
| 1266 | + | |
1259 | 1267 | | |
1260 | | - | |
1261 | | - | |
1262 | | - | |
1263 | | - | |
1264 | | - | |
1265 | | - | |
1266 | | - | |
1267 | | - | |
1268 | | - | |
1269 | | - | |
1270 | | - | |
| 1268 | + | |
| 1269 | + | |
| 1270 | + | |
| 1271 | + | |
| 1272 | + | |
1271 | 1273 | | |
| 1274 | + | |
1272 | 1275 | | |
1273 | | - | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
1281 | 1276 | | |
1282 | 1277 | | |
1283 | 1278 | | |
| |||
0 commit comments