Commit 9dfa0eb
## Summary
Fixes #4501 — `KeyError: key :consider_flushed? not found in: nil` in
`Electric.Shapes.Consumer.process_txn_fragment/2`.
A shape consumer could **suspend (terminate to reclaim memory) on its
idle timeout while still holding a `pending_txn`** for an in-flight
multi-fragment transaction. The producer's `EventRouter` tracks "this
shape already saw the begin for the current xid" keyed by
`shape_handle`, independently of consumer liveness — so when a later
fragment of that transaction arrived, `ConsumerRegistry` started a fresh
consumer and delivered a `has_begin?: false` fragment to it. The fresh
consumer has `pending_txn: nil`, so `process_txn_fragment/2`
dereferenced `nil` at `txn.consider_flushed?`.
## Fix
`consumer_can_suspend?/1` now also requires `is_nil(state.pending_txn)`.
A consumer that is mid-transaction hibernates instead of suspending, and
only suspends once the transaction completes and it goes idle again.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Oleksii Sholik <oleksii@sholik.dev>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d3e1a64 commit 9dfa0eb
3 files changed
Lines changed: 77 additions & 1 deletion
File tree
- .changeset
- packages/sync-service
- lib/electric/shapes
- test/electric/shapes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
399 | 399 | | |
400 | 400 | | |
401 | 401 | | |
| 402 | + | |
402 | 403 | | |
403 | 404 | | |
404 | 405 | | |
| |||
416 | 417 | | |
417 | 418 | | |
418 | 419 | | |
419 | | - | |
| 420 | + | |
420 | 421 | | |
421 | 422 | | |
422 | 423 | | |
| |||
Lines changed: 70 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1461 | 1461 | | |
1462 | 1462 | | |
1463 | 1463 | | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
1464 | 1534 | | |
1465 | 1535 | | |
1466 | 1536 | | |
| |||
0 commit comments