Skip to content

Fix concurrent intercom reply waiters#33

Open
danrom85 wants to merge 1 commit into
nicobailon:mainfrom
danrom85:fix/concurrent-reply-waiters
Open

Fix concurrent intercom reply waiters#33
danrom85 wants to merge 1 commit into
nicobailon:mainfrom
danrom85:fix/concurrent-reply-waiters

Conversation

@danrom85

@danrom85 danrom85 commented Jun 7, 2026

Copy link
Copy Markdown

Summary

Fixes a crash/race condition when multiple reply-waiting intercom calls run concurrently.

Previously, pi-intercom used a single module-scoped replyWaiter. If two ask / supervisor-style calls were active at the same time, the second waiter could hit Already waiting for a reply. In Node versions where unhandled rejections are thrown, this can
terminate the Pi process.

This PR changes reply waiting to support independent concurrent waiters keyed by replyTo / question ID.

Changes

  • Replace singleton replyWaiter with a Map<string, ReplyWaiter>
  • Resolve replies by replyTo, allowing concurrent asks to coexist
  • Reject all outstanding waiters on disconnect/shutdown
  • Clean up only the current waiter on delivery/cancel/error
  • Add .catch(() => undefined) for ask-path reply promises to avoid unhandled rejection crashes
  • Add regression coverage for concurrent supervisor asks resolving independently, including out-of-order replies

Validation

  • Ran npm install
  • Ran npm test
  • Result: 37 tests passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant