Commit 58f119a
Fix returning an array of txids from an Electric collection handler (#795)
* test: add failing test for array txid bug in electric collection
This test demonstrates issue #793 where returning an array of txids
from a collection handler (e.g., `return { txid: [txid1, txid2] }`)
causes a TimeoutWaitingForTxIdError instead of properly waiting for
all txids to be seen in the sync stream.
The test shows that when a handler returns multiple txids, the
processMatchingStrategy function doesn't correctly handle the array,
even though it has code that appears to support arrays.
* test: make array txid test more realistic with staggered arrivals
Update the test to send txids on different ticks (50ms and 100ms apart)
rather than in a single batch. This better simulates real-world
conditions where multiple txids rarely arrive together.
* fix: correct array txid handling in electric collection handlers
The bug was in processMatchingStrategy when handling arrays of txids.
Using `.map(awaitTxId)` directly caused Array.map() to pass three
arguments (element, index, array), and the index was being interpreted
as the timeout parameter of awaitTxId.
For example:
- awaitTxId(txid1, 0) → timeout 0ms (immediate timeout!)
- awaitTxId(txid2, 1) → timeout 1ms (immediate timeout!)
This caused TimeoutWaitingForTxIdError even though the txids were
being sent correctly via the sync stream.
The fix uses an arrow function to ensure only the txid is passed:
await Promise.all(result.txid.map((txid) => awaitTxId(txid)))
This allows the timeout to use its default value of 5000ms.
Fixes #793
* chore: add changeset for array txid fix
* test: fix TypeScript errors in array txid test
Add non-null assertions for array element access to fix type errors
where txids[0] and txids[1] could theoretically be undefined.
* chore: remove obvious comment
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent ebc5ed2 commit 58f119a
3 files changed
Lines changed: 84 additions & 1 deletion
File tree
- .changeset
- packages/electric-db-collection
- src
- tests
| 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 | |
|---|---|---|---|
| |||
533 | 533 | | |
534 | 534 | | |
535 | 535 | | |
536 | | - | |
| 536 | + | |
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
672 | 672 | | |
673 | 673 | | |
674 | 674 | | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
675 | 753 | | |
676 | 754 | | |
677 | 755 | | |
| |||
0 commit comments