Skip to content

Fix: reject midInProcess callback on close#54

Open
tayou89 wants to merge 1 commit intost-one-io:masterfrom
tayou89:fix/reject-midInProcess-on-close
Open

Fix: reject midInProcess callback on close#54
tayou89 wants to merge 1 commit intost-one-io:masterfrom
tayou89:fix/reject-midInProcess-on-close

Conversation

@tayou89
Copy link
Copy Markdown

@tayou89 tayou89 commented Mar 26, 2026

Summary

Fixes #53midInProcess callback is not invoked when close() is called, causing promises to hang forever.

  • Reject midInProcess with the close error (or default "service unavailable") before nulling, using the same process.nextTick pattern as midQueue items
  • Add tests for both error-forwarding and default-error scenarios
  • Handle unhandled promise rejections in existing sendMid tests

The Problem

When close() is called, midQueue items get their callbacks properly rejected (lines 425-430), but midInProcess is silently set to null (line 432). Any pending callback/Promise for the in-flight MID hangs forever.

The Fix

if (this.midInProcess) {
    let e = err || new Error("service unavailable");
    let mid = this.midInProcess;
    this.midInProcess = null;
    process.nextTick(() => mid.doCallback(e));
} else {
    this.midInProcess = null;
}

Test plan

  • New test: close(err) forwards the error to midInProcess callback
  • New test: close() without args uses default "service unavailable"
  • All existing tests pass (except pre-existing timeout in keepAlive test)
  • Updated sendMid tests to handle the now-expected promise rejection

When close() is called, midQueue items are properly rejected with an
error callback, but midInProcess is silently set to null. This causes
the pending callback/promise to hang forever when a connection drops
while a MID is being processed.

Reject midInProcess with the close error (or default "service
unavailable") before nulling, using the same process.nextTick pattern
as midQueue items.

Add tests for both error-forwarding and default-error cases.
Handle unhandled promise rejections in existing sendMid tests.
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.

midInProcess callback not invoked on close, causing promise to hang

1 participant