Skip to content

Fix broker shutdown hang on unresponsive socket#300

Open
dhruvac29 wants to merge 2 commits intoopenai:mainfrom
dhruvac29:fix-broker-shutdown-timeout
Open

Fix broker shutdown hang on unresponsive socket#300
dhruvac29 wants to merge 2 commits intoopenai:mainfrom
dhruvac29:fix-broker-shutdown-timeout

Conversation

@dhruvac29
Copy link
Copy Markdown

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 .

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95c05c111b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread tests/broker-lifecycle.test.mjs Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR prevents SessionEnd from hanging indefinitely by adding a bounded timeout to the broker shutdown RPC and ensuring the shutdown socket is cleaned up via a single guarded completion path.

Changes:

  • Add an optional timeoutMs (default 5000) to sendBrokerShutdown and resolve on timeout.
  • Centralize shutdown completion logic for data, error, close, and timeout; destroy the socket during cleanup.
  • Add a regression test for the “accepts connection but never responds” broker behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
plugins/codex/scripts/lib/broker-lifecycle.mjs Adds a bounded timeout + guarded cleanup to prevent indefinite shutdown waits.
tests/broker-lifecycle.test.mjs Introduces a regression test for an unresponsive broker shutdown socket.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/broker-lifecycle.test.mjs Outdated
Comment thread tests/broker-lifecycle.test.mjs
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.

sendBrokerShutdown has no timeout — SessionEnd hook can hang indefinitely

2 participants