Skip to content

Commit 48a68e6

Browse files
Mark HendersonMark Henderson
authored andcommitted
fix: harden share-next dispose to avoid race on queue iteration
1 parent 663546a commit 48a68e6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

packages/opencode/src/share/share-next.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,12 @@ export namespace ShareNext {
8585
log.error("failed to unsubscribe", { error })
8686
}
8787
}
88-
// Clear pending timeouts
89-
for (const entry of queue.values()) {
88+
// Hardened: snapshot and clear atomically to avoid race during iteration
89+
const pending = Array.from(queue.values())
90+
queue.clear()
91+
for (const entry of pending) {
9092
clearTimeout(entry.timeout)
9193
}
92-
queue.clear()
9394
log.info("disposed share-next subscriptions")
9495
}
9596

0 commit comments

Comments
 (0)