fix: close Browserbase sessions on HTTP disconnect#189
Open
RitwijParmar wants to merge 1 commit into
Open
Conversation
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.
What changed
Closes #187.
This wires the per-client HTTP MCP lifecycle back to the Browserbase session lifecycle:
SessionManager.closeAllSessions()withServerListtransport.onclosecallserverList.close(server)instead of only removing the transport routing entryServerList.close()idempotent/re-entrant safe, soserver.close()triggeringtransport.onclosedoes not double-close the same server/sessioncloseAll()to use the same cleanup path as single-server shutdownWhy
In long-running
--portmode, a client can disconnect without calling theendtool. Before this change, the transport entry was removed but the MCP server, SessionManager, Stagehand instance, and Browserbase cloud session could stay alive until timeout; withkeepAlive, that can turn into a real session-minute leak.Validation
./node_modules/.bin/tsc --noEmit./node_modules/.bin/eslint src/server.ts src/index.ts src/transport.ts src/server.test.tsI also added focused Vitest coverage for cleanup ordering and re-entrant close behavior. I couldn't run Vitest locally because macOS rejected the downloaded Rolldown native binding in this checkout, but the test is included for CI.