fix: close browser after export#4373
Conversation
|
@howenyap is attempting to deploy a commit to the modsbot's projects Team on Vercel. A member of the Team first needs to authorize it. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4373 +/- ##
==========================================
+ Coverage 54.52% 56.39% +1.86%
==========================================
Files 274 317 +43
Lines 6076 6962 +886
Branches 1455 1679 +224
==========================================
+ Hits 3313 3926 +613
- Misses 2763 3036 +273 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@greptile |
first greptile scan kinda nervous |
Confidence Score: 5/5Safe to merge — the change is a targeted cleanup of a genuine resource leak with correct finally-block placement and no regressions to the happy path. Both changed files are small and self-contained. The fix correctly closes the browser via a try/finally in the handler, and defensively closes it inside No files require special attention.
|
| Filename | Overview |
|---|---|
| export/src/render-serverless.ts | Explicit return type added to open; now returns { browser, page } instead of just page; browser is closed in a try/catch if page initialisation fails |
| export/src/handler.ts | Destructures browser from render.open(); wraps performExport in try/finally so browser.close() is always called, replacing the old page.close() call |
Sequence Diagram
sequenceDiagram
participant H as handler.ts
participant R as render-serverless.ts
participant B as Browser
participant P as Page
H->>R: open(url)
R->>B: puppeteer.launch()
B-->>R: browser
R->>P: browser.newPage()
P-->>R: page
R->>P: page.goto(url)
R->>P: setViewport(page)
R-->>H: "{ browser, page }"
H->>H: performExport(response, page, data)
note over H: try/finally
H->>B: browser.close()
B->>P: (implicitly closes page)
note over R: If page init fails:
R->>B: browser.close()
R-->>H: throws error
Reviews (2): Last reviewed commit: "Merge branch 'master' into howen/fix-unc..." | Re-trigger Greptile
b79003c to
2bf0914
Compare
|
@greptile |
Context
The serverless export service opens a browser but only returns the page handler
Then, cleanup only closes the page, leaving the browser handle open.
Implementation
openfunctionOther Information
Disclaimer:
I found this leak with Codex Security and told @ravern about it!