fix: resolve server.close recursion, add MV3 keep-alive ping, and clean up Windows port kill - #201
Open
dfgr wants to merge 1 commit into
Open
Conversation
…ping, and clean up Windows port kill
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
This PR addresses three critical stability issues affecting the core MCP server and browser connection reliability:
Infinite Recursion on
server.close()(CWE-674 / Closes DoS via infinite recursion in server.close() on client disconnect (CWE-674) #163):server.closeoverride was recursively callingawait server.close(), leading to an immediateRangeError: Maximum call stack size exceededwhenever a client disconnected or the server was closed.originalClose = server.close.bind(server)and invoke it prior to cleaning up the WebSocket server and context.Chrome Manifest V3 Background Worker Idle Disconnect (Resolves MV3 service worker killed on idle — popup shows stale 'Disconnect' state, WebSocket never reconnects #192):
"No connection to browser extension".websocket.ping()heartbeat inserver.ts. Active ping frames keep the Chromium network stack and background worker alive during idle periods. Also clears stale WebSocket references inContexton close.Windows Port Kill Stderr Pollution:
netstat -ano | findstr :${port}returns exit code 1 if no process is currently listening on the port. Even though wrapped intry/catch,console.errorlogged an extensive error stack trace tostderr, causing some strict MCP client launchers to treat initialization as failed.2>nul), pass{ stdio: 'ignore' }, and ignore expected non-zero exits when the port is already free.Testing
browser_snapshot,browser_navigate), and termination without recursion crashes or unhandled exceptions.