Skip to content

Commit 1736095

Browse files
committed
More fixes around streams ending.
1 parent 929c7b0 commit 1736095

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

modules/module-mongodb-storage/src/storage/implementation/MongoSyncBucketStorage.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,9 +695,14 @@ export class MongoSyncBucketStorage
695695
while (true) {
696696
// If the stream is idle, we wait a max of a minute (CHECKPOINT_TIMEOUT_MS)
697697
// before we get another checkpoint, to avoid stale checkpoint snapshots.
698-
const timeout = timers.setTimeout(CHECKPOINT_TIMEOUT_MS, null, { signal });
698+
const timeout = timers
699+
.setTimeout(CHECKPOINT_TIMEOUT_MS, { done: false }, { signal })
700+
.catch(() => ({ done: true }));
699701
try {
700-
await Promise.race([stream.next(), timeout]);
702+
const result = await Promise.race([stream.next(), timeout]);
703+
if (result.done) {
704+
break;
705+
}
701706
} catch (e) {
702707
if (e.name == 'AbortError') {
703708
break;
@@ -706,6 +711,7 @@ export class MongoSyncBucketStorage
706711
}
707712

708713
if (signal.aborted) {
714+
// Would likely have been caught by the signal on the timeout or the upstream stream, but we check here anyway
709715
break;
710716
}
711717

0 commit comments

Comments
 (0)