Skip to content

fix(lighthouse): ensure teardown runs when withPage throws#757

Merged
Kikobeats merged 1 commit into
masterfrom
fix/lighthouse-context-leak
May 17, 2026
Merged

fix(lighthouse): ensure teardown runs when withPage throws#757
Kikobeats merged 1 commit into
masterfrom
fix/lighthouse-context-leak

Conversation

@Kikobeats
Copy link
Copy Markdown
Member

@Kikobeats Kikobeats commented May 17, 2026

Summary

  • Wrap the withPage call in try/finally so the teardown callback always executes, preventing browser context leaks when lighthouse audits fail (timeouts, navigation errors, etc.)
  • No changes needed in microlink/api — the existing teardown(() => browserless.close(id)) registration works correctly once the teardown is guaranteed to run

Context

When withPage() throws, the teardown callback registered by consumers (e.g. browserless.close(id) in microlink/api) was never called because control flow skipped the teardown line. This caused browser contexts to leak on every failed lighthouse audit.

Closes #693

Made with Cursor


Note

Low Risk
Low risk control-flow change that ensures teardown runs even when browserless.withPage throws, reducing the chance of leaked browser contexts.

Overview
Ensures browser resources are always cleaned up by wrapping the browserless.withPage(...)() call in try/finally and moving the teardown invocation into the finally block.

This guarantees teardown executes on Lighthouse failures/timeouts instead of being skipped on exceptions.

Reviewed by Cursor Bugbot for commit e653fb9. Bugbot is set up for automated code reviews on this repo. Configure here.

Wrap the withPage call in try/finally so the teardown callback
always executes, preventing browser context leaks on audit failures.

Closes #693

Co-authored-by: Cursor <cursoragent@cursor.com>
@Kikobeats Kikobeats merged commit be75012 into master May 17, 2026
21 checks passed
@Kikobeats Kikobeats deleted the fix/lighthouse-context-leak branch May 17, 2026 21:01
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage is 74.715%fix/lighthouse-context-leak into master. No base build found for master.

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.

[Detail Bug] CLI Lighthouse runs can leak browser contexts when audits fail

2 participants