Skip to content

midInProcess callback not invoked on close, causing promise to hang #53

@tayou89

Description

@tayou89

Bug Description

When SessionControlClient.close() is called (e.g., due to a connection drop), callbacks for items in midQueue are properly rejected with an error. However, the currently active MID (midInProcess) is silently set to null without invoking its callback.

This causes the pending Promise/callback to hang forever, leading to memory leaks and application freezes in production environments with unreliable network connections.

Steps to Reproduce

  1. Connect to a controller
  2. Send a command (e.g., request("readTimeUpload"))
  3. While the command is in-flight (waiting for response), the connection drops
  4. close() is called (either manually or via the stream.on("close") handler)
  5. The callback/Promise from step 2 never resolves or rejects

Expected Behavior

The midInProcess callback should be rejected with the close error (or a default "service unavailable" error), consistent with how midQueue items are handled.

Relevant Code

src/sessionControlClient.js, close() method (line 432):

// midQueue items are properly rejected (lines 425-430)
if (this.midQueue && this.midQueue.length > 0) {
    let e = new Error("service unavailable");
    this.midQueue.forEach(item => {
        process.nextTick(() => item.doCallback(e));
    });
}

// But midInProcess is silently dropped
this.midInProcess = null;  // <-- callback never invoked

Environment

  • node-open-protocol version: 1.1.1
  • Node.js version: v20.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions