fix: prevent sub-agent hang after OAuth callback server is started#43
Open
blai wants to merge 1 commit intonicobailon:mainfrom
Open
fix: prevent sub-agent hang after OAuth callback server is started#43blai wants to merge 1 commit intonicobailon:mainfrom
blai wants to merge 1 commit intonicobailon:mainfrom
Conversation
OAuth changes added initializeOAuth() on session_start, which starts an HTTP callback server. Two defects caused sub-agent processes to hang indefinitely after completing their task: 1. session_shutdown did not call shutdownOAuth(), so the callback server was never closed when a session ended. Fix: call shutdownOAuth() alongside shutdownState() in the session_shutdown handler. 2. The HTTP server was created without server.unref(), making it a strong event- loop reference. Even if shutdown ran cleanly, any race where the handler was skipped (e.g. SIGKILL, uncaught throw) would keep the process alive. Fix: call server.unref() immediately after bind so Node treats the server as a background resource and exits naturally when no foreground work remains. Tests: added regression coverage in two new suites: - index-lifecycle: asserts shutdownOAuth is called on session_shutdown - mcp-callback-server-unref: asserts server.unref() is called on successful bind and NOT called on a failed bind (EADDRINUSE)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OAuth changes added initializeOAuth() on session_start, which starts an HTTP callback server. Two defects caused sub-agent processes to hang indefinitely after completing their task:
session_shutdown did not call shutdownOAuth(), so the callback server was never closed when a session ended. Fix: call shutdownOAuth() alongside shutdownState() in the session_shutdown handler.
The HTTP server was created without server.unref(), making it a strong event- loop reference. Even if shutdown ran cleanly, any race where the handler was skipped (e.g. SIGKILL, uncaught throw) would keep the process alive. Fix: call server.unref() immediately after bind so Node treats the server as a background resource and exits naturally when no foreground work remains.
Tests: added regression coverage in two new suites: