Skip to content

fix(reports): stop reports crashing or hanging when Chromium closes - #48

Merged
HarshMN2345 merged 2 commits into
mainfrom
fix-lighthouse-crash-on-chromium-close
Dec 1, 2026
Merged

HarshMN2345 merged 2 commits into
mainfrom
fix-lighthouse-crash-on-chromium-close

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

What changed

  • Logs unhandled promise rejections instead of letting them exit the process.
  • A report now fails as soon as its context closes, and after 120 s at most, instead of waiting on Lighthouse forever.

Lighthouse sends CDP commands from event listeners nothing awaits. When Chromium closes during a report (a memory budget restart since 0.3.16, or a crash), those commands reject outside any request and Bun exits, taking every capture in flight with it. Depending on when Chromium closes, Lighthouse can also never settle, so the request hangs until the caller gives up.

Tested

  • bun run lint, bun run check, bun run type-check
  • Built the image and killed Chromium 3–30 s into a report on bbc.com, 10 times.
    • Before: the server exited at 11 s (Protocol error (Runtime.evaluate): Session closed); with only the rejection handler, reports killed at 11 s and 13 s hung past the 90 s client timeout.
    • After: every report returned 400 within ~1 s of the kill, the server stayed up, and no unhandled rejections were logged.
  • Reports on example.com and cnn.com afterwards returned 200 (cnn.com took 86 s, under the 120 s limit). The 120 s timeout path itself was not hit.

@appwrite

appwrite Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
37e14e1 Reviewed Reviewed 🔵 A · Mergeable after minor fixes ✅ Approved View review

The previously reported process-level rejection regression-test gap remains open.

The reports handler now races Lighthouse against browser-context closure and a 120-second audit deadline, then cleans up the timer and context. The server also logs unhandled promise rejections so Lighthouse event-listener failures do not take down the process.

Latest changes: The newest commits add browser-close and timeout promises around Lighthouse, returning through the existing error handling when either wins the race.

Fix with agent prompt
### Issue 1
src/server.ts:13-15
**Add a regression test for process-level rejection recovery**

Could we add a regression test that causes a CDP rejection during an active report and then verifies the server still handles a subsequent request? The existing browser recovery test kills Chromium before a screenshot, so it does not reliably exercise the unhandled-rejection behavior added here.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Walkthrough (2)
File Change
src/routes/reports.ts Fail report requests when Chromium closes or Lighthouse exceeds the audit deadline.
src/server.ts Log unhandled promise rejections to keep the server process running.
Still open from earlier reviews (1)
  • 🟡 Add a regression test for process-level rejection recovery · src/server.ts:13

Reviewed the commits since 9a0f56f

Tip

Comment @appwrite review to re-run, or mention @appwrite with a question.

@appwrite appwrite Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

Comment thread src/server.ts
Comment on lines +13 to +15
process.on("unhandledRejection", (reason) => {
console.error("Unhandled rejection:", reason);
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Add a regression test for process-level rejection recovery

Could we add a regression test that causes a CDP rejection during an active report and then verifies the server still handles a subsequent request? The existing browser recovery test kills Chromium before a screenshot, so it does not reliably exercise the unhandled-rejection behavior added here.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/server.ts
Line: 13-15

Comment:
**Add a regression test for process-level rejection recovery**

Could we add a regression test that causes a CDP rejection during an active report and then verifies the server still handles a subsequent request? The existing browser recovery test kills Chromium before a screenshot, so it does not reliably exercise the unhandled-rejection behavior added here.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Docker Image Stats

Metric Value
Image Size 871MB
Memory Usage 109.9MiB
Cold Start Time 1.02s
Screenshot Time 1.18s

Screenshot benchmark: Average of 3 runs on https://appwrite.io

@HarshMN2345 HarshMN2345 changed the title fix(reports): keep the server up when Chromium closes mid-report fix(reports): stop reports crashing or hanging when Chromium closes Dec 1, 2026
@HarshMN2345
HarshMN2345 merged commit fa8c7a9 into main Dec 1, 2026
5 checks passed
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.

1 participant