codex-plugin-cc icon indicating copy to clipboard operation
codex-plugin-cc copied to clipboard

Fix broker shutdown hang on unresponsive socket

Open dhruvac29 opened this issue 7 months ago • 1 comments

Summary

Fixes a SessionEnd hang where sendBrokerShutdown could wait indefinitely if the broker accepted the shutdown socket connection but never replied, errored, or closed.

This adds a bounded timeout to the shutdown RPC and uses a single guarded cleanup path for data, error, close, and timeout.

Changes

  • Add timeoutMs = 5000 to sendBrokerShutdown
  • Resolve shutdown on timeout instead of waiting forever
  • Destroy the socket during cleanup
  • Add a regression test for a broker that accepts broker/shutdown but never responds

Testing

node --test tests/broker-lifecycle.test.mjs
npm test

Full suite passed locally: 87 passed, 0 failed.

Fixes #288 .

dhruvac29 avatar May 05 '26 21:05 dhruvac29

Confirmed on plugin v1.0.4 (Node 26, macOS). Reproduces as SessionEnd hook ... failed: Hook cancelled on nearly every session exit.

Applied this fix's approach locally — bounded timeout in sendBrokerShutdown that resolves (not rejects) so handleSessionEnd still reaches teardownBrokerSession/clearBrokerSession. Verified against three paths: dead endpoint (~6ms), a broker that connects but never replies (~1s, was previously hanging to the 5s hook kill), and the normal reply path (unaffected).

One minor note: a 1s default bounds the wait well under the 5s hook budget; 5s leaves no cushion before the harness cancels the hook. Either works for the hang itself, but a sub-budget default also fixes the "Hook cancelled" message, not just the indefinite hang.

agent-ptolemy avatar Jun 15 '26 09:06 agent-ptolemy