fix(mcp): stop oauth callback server#24866
Open
Hona wants to merge 1 commit intoanomalyco:devfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Stops the MCP OAuth callback HTTP server once OAuth is completed/removed or when the MCP service is finalized, preventing the callback server from keeping the process alive after auth flows.
Changes:
- Introduces a shared
stopOAuthCallbackEffect that closes the callback server (errors ignored). - Stops the callback server in the MCP service finalizer and after
authenticate()/finishAuth()viaEffect.ensuring(...). - Stops the callback server when OAuth credentials are removed (
removeAuth).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| type Transport = StdioClientTransport | StreamableHTTPClientTransport | SSEClientTransport | ||
|
|
||
| const stopOAuthCallback = Effect.tryPromise(() => McpOAuthCallback.stop()).pipe(Effect.ignore) |
Comment on lines
+835
to
836
| }).pipe(Effect.ensuring(stopOAuthCallback)) | ||
| }) |
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.
Summary
Repro
I reproduced the leak with a temporary Bun script that starts the same callback server repeatedly:
Without
McpOAuthCallback.stop(), this printstrueand the process stays alive until killed by the 3s command timeout.With
McpOAuthCallback.stop(), the server closes and the same repro exits in ~1.3s.User-Facing Impact
This is not unbounded memory growth. It is a live HTTP server handle leak.
opencode mcp auth <server>startAuth/finishAuthVerification
bun typecheckfrompackages/opencodebun turbo typecheck