Skip to content

Commit b6639ad

Browse files
committed
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
1 parent 3bdb5ab commit b6639ad

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

packages/electric-db-collection/src/electric.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ export function electricCollectionOptions(
506506
if (result && `txid` in result) {
507507
// Handle both single txid and array of txids
508508
if (Array.isArray(result.txid)) {
509-
await Promise.all(result.txid.map(awaitTxId))
509+
// Use arrow function to avoid passing map's index as timeout parameter
510+
await Promise.all(result.txid.map((txid) => awaitTxId(txid)))
510511
} else {
511512
await awaitTxId(result.txid)
512513
}

packages/electric-db-collection/tests/electric.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ describe(`Electric Integration`, () => {
697697
},
698698
{ headers: { control: `up-to-date` } },
699699
])
700-
}, 50)
700+
}, 1)
701701

702702
setTimeout(() => {
703703
subscriber([
@@ -711,7 +711,7 @@ describe(`Electric Integration`, () => {
711711
},
712712
{ headers: { control: `up-to-date` } },
713713
])
714-
}, 100)
714+
}, 2)
715715

716716
// Return array of txids - this is the pattern that's failing
717717
return { txid: txids }

0 commit comments

Comments
 (0)