Skip to content

fix: run each Lighthouse report in its own process - #51

Merged
HarshMN2345 merged 4 commits into
mainfrom
fix-lighthouse-leak
Dec 2, 2026
Merged

HarshMN2345 merged 4 commits into
mainfrom
fix-lighthouse-leak

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

Lighthouse's trace engine keeps each report's trace in module-level state (FlowsHandler, RendererHandler, ...), so the server process grew with every report: 201 MB to 1,538 MB over 10 bbc.com reports in a local loop.

Each audit now runs in a short-lived bun src/audit.ts child that gets the URL, viewport, thresholds and formats on stdin and writes the report to stdout. All its memory goes back when it exits.

  • The 120s deadline is the spawn timeout; the child is killed when the context closes or the request ends.
  • Lighthouse already audits in its own tab over port 9222, so behaviour is unchanged.

Local run: server RSS 59 MB at start, 100 MB after 5 reports, 100 MB after 10.

@appwrite

appwrite Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Code review

Commit Status Tier Verdict Details
c9d05ad Reviewed Reviewed 🟢 S · Ready to merge ✅ Approved View review

The request abort signal closes the previously reported cancellation gap, and no remaining issue was found.

Each Lighthouse report runs in a short-lived bun src/audit.ts subprocess, with the request URL and audit options passed over stdin and the generated report returned over stdout. The route bounds the child with a 120-second timeout and terminates it when the browser context closes or the client request is aborted, then cleans up the browser and egress resources.

Latest changes: The newest change passes req.signal to Bun.spawn, so a client disconnect aborts the audit subprocess, and updates the comment to include request cancellation.

Walkthrough (2)
File Change
src/audit.ts Runs a Lighthouse audit as a separate process and writes the report to stdout.
src/routes/reports.ts Spawns the audit subprocess, applies timeout and cancellation handling, and cleans up child and browser resources.
Fixed since the last review (1)
  • Abort the audit when the client disconnects · src/routes/reports.ts:117

Reviewed the commits since 5c92bcd

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 · See the inline comments. Summary

Comment thread src/routes/reports.ts Resolved
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Docker Image Stats

Metric Value
Image Size 871MB
Memory Usage 88.83MiB
Cold Start Time 1.05s
Screenshot Time .99s

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

@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 S · Looks good to merge. Summary

@HarshMN2345
HarshMN2345 merged commit d617124 into main Dec 2, 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