Commit 3d4c962
fix(electric-db-collection): prevent orphan transactions after must-refetch in progressive mode
When a `must-refetch` message is received in progressive mode, it starts a
transaction with `begin()` and calls `truncate()`. This resets `hasReceivedUpToDate`
to `false`, causing `isBufferingInitialSync()` to return `true`.
The bug: subsequent messages after must-refetch were being buffered instead of
written to the existing transaction. When `up-to-date` was received, the atomic
swap code would create a NEW transaction, leaving the first transaction (from
must-refetch) uncommitted forever. This "orphan transaction" caused the collection
to become corrupted with undefined values.
The fix: Add `&& !transactionStarted` checks to 5 places so that when a transaction
is already started (from must-refetch), messages are written directly to it instead
of being buffered for atomic swap.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Opus 4.5 <[email protected]>1 parent 2c2420c commit 3d4c962
File tree
2 files changed
+31
-5
lines changed- .changeset
- packages/electric-db-collection/src
2 files changed
+31
-5
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1303 | 1303 | | |
1304 | 1304 | | |
1305 | 1305 | | |
1306 | | - | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
1307 | 1312 | | |
1308 | 1313 | | |
1309 | 1314 | | |
| |||
1338 | 1343 | | |
1339 | 1344 | | |
1340 | 1345 | | |
1341 | | - | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
1342 | 1349 | | |
1343 | 1350 | | |
1344 | 1351 | | |
| |||
1352 | 1359 | | |
1353 | 1360 | | |
1354 | 1361 | | |
1355 | | - | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
1356 | 1365 | | |
1357 | 1366 | | |
1358 | 1367 | | |
| |||
1365 | 1374 | | |
1366 | 1375 | | |
1367 | 1376 | | |
1368 | | - | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
1369 | 1380 | | |
1370 | 1381 | | |
1371 | 1382 | | |
| |||
1405 | 1416 | | |
1406 | 1417 | | |
1407 | 1418 | | |
1408 | | - | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
1409 | 1426 | | |
1410 | 1427 | | |
1411 | 1428 | | |
| |||
0 commit comments