Skip to content

fix: make CDP browser shutdown reentrant - #5626

Merged
ashwinsingh2007 merged 1 commit into
mainfrom
fix/reentrant-browser-close
Oct 20, 2026
Merged

ashwinsingh2007 merged 1 commit into
mainfrom
fix/reentrant-browser-close

Conversation

@artiom

@artiom artiom commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Description

Make ChromiumCDP.close() safe when a close listener calls it again. Previously the nested call cleared the browser reference before the outer call removed listeners, causing a null dereference and duplicate close events.

Publish one pending shutdown promise before notifying listeners. Re-entrant and concurrent callers await the same underlying shutdown rather than returning early. Capture the browser before scheduling shutdown so an unexpected disconnect cannot erase the reference. Clear the pending promise after completion so later lifecycle calls retain the existing behavior.

Verification

  • Reproduced the null removeAllListeners error with an actual Chromium instance before the fix.
  • npm run build:ts passes.
  • DEBUG=quiet npx mocha --no-package --timeout 45000 build/browsers/browsers.cdp.spec.js: 37 passing. The regression delays the underlying close to check that the nested caller waits, emits only one close event, and permits repeated close calls after shutdown. Existing socket lifecycle, blocked-navigation and authentication tests pass unchanged.
  • Targeted Prettier check and git diff --check pass.
  • npm test reached 110 passing, then stopped in the Browser scratch directories setup because the separate ChromeCDP binary was unavailable. The full multi-browser suite has not passed locally; Chromium was installed and exercised.

No API, credential, or network-policy changes. Shutdown notification now runs in a microtask so the shared promise exists before listeners can re-enter.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed browser shutdown behavior when a close event triggers another close request. The nested request now waits for shutdown to finish, and repeated close calls no longer cause duplicate close events. The browser is also marked as stopped as shutdown begins, providing more consistent state during the process.

Devin Review

@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Team
  • Run ID: b0024f0a-f7a9-429c-a6f3-26c28a6256f9
📥 Commits

Reviewing files that changed from the base of the PR and between d4eb442 and bf2a5ef.

📒 Files selected for processing: 2
  • src/browsers/browsers.cdp.spec.ts
  • src/browsers/browsers.cdp.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

ChromiumCDP.close() now coordinates concurrent and reentrant shutdown calls with one in-progress promise. A regression test checks that a nested close call waits for shutdown, the close event fires once, and later close calls emit no additional event.

Changes

Chromium shutdown

Layer / File(s) Summary
Close coordination and regression coverage
src/browsers/browsers.cdp.ts, src/browsers/browsers.cdp.spec.ts
close() returns the existing shutdown promise when shutdown is in progress. It clears browser state before awaiting the captured browser’s close and clears the promise after completion. The test covers a nested close call from a close listener and checks event and running state.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: joelgriffith

Merge Risk: ⚪ Minimal · up to bf2a5

Concurrent shutdown callers now wait for the same close operation. No issue identified here prevents merging after normal checks.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: making CDP browser shutdown reentrant.
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit watched the close event glow,
One promise kept the calls in tow.
The browser closed; the state was clear,
No second close event appeared.
The rabbit hopped away, ears high.

Comment @coderabbitai help to get the list of available commands.

@artiom
artiom marked this pull request as ready for review October 19, 2026 14:32

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

artiom commented Oct 19, 2026

Copy link
Copy Markdown
Contributor Author

Current head is ready for review. All applicable CI checks passed, including Chromium, Chrome, Edge, Firefox, WebKit, multi-image tests, lint, formatting, leak checks and CodeQL. The optional Dependabot automerge job was skipped. CodeRabbit and Devin Review reported no actionable findings; no review threads are unresolved. The branch is mergeable and awaits human approval. Local focused tests passed (37); the separately disclosed local full-suite limitation does not apply to the successful CI matrix.

@ashwinsingh2007
ashwinsingh2007 merged commit 19841b6 into main Oct 20, 2026
17 checks passed
@ashwinsingh2007
ashwinsingh2007 deleted the fix/reentrant-browser-close branch October 20, 2026 09:03
artiom pushed a commit that referenced this pull request Oct 21, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.57.2](v2.57.1...v2.57.2)
(2026-10-21)


### Bug Fixes

* make CDP browser shutdown reentrant
([#5626](#5626))
([19841b6](19841b6))
* preserve launch arguments alongside legacy switches
([#5630](#5630))
([eff44d1](eff44d1))


### Build System & Runtime

* bump Node to 24.22.1
([#5631](#5631))
([d2e948c](d2e948c))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: browserless-actions-bot[bot] <186328842+browserless-actions-bot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants