Skip to content

fix: close Browserbase sessions on HTTP disconnect#189

Open
RitwijParmar wants to merge 1 commit into
browserbase:mainfrom
RitwijParmar:codex/browserbase-http-session-cleanup
Open

fix: close Browserbase sessions on HTTP disconnect#189
RitwijParmar wants to merge 1 commit into
browserbase:mainfrom
RitwijParmar:codex/browserbase-http-session-cleanup

Conversation

@RitwijParmar

Copy link
Copy Markdown

What changed

Closes #187.

This wires the per-client HTTP MCP lifecycle back to the Browserbase session lifecycle:

  • registers each MCP server's SessionManager.closeAllSessions() with ServerList
  • makes transport.onclose call serverList.close(server) instead of only removing the transport routing entry
  • makes ServerList.close() idempotent/re-entrant safe, so server.close() triggering transport.onclose does not double-close the same server/session
  • updates closeAll() to use the same cleanup path as single-server shutdown

Why

In long-running --port mode, a client can disconnect without calling the end tool. Before this change, the transport entry was removed but the MCP server, SessionManager, Stagehand instance, and Browserbase cloud session could stay alive until timeout; with keepAlive, 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.ts

I 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.

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.

HTTP transport orphans Browserbase sessions on client disconnect — cleanup path is unwired

1 participant