fix(scraper): don't orphan the browser when a portal session fails to acquire#171
Open
delabrcd wants to merge 1 commit into
Open
fix(scraper): don't orphan the browser when a portal session fails to acquire#171delabrcd wants to merge 1 commit into
delabrcd wants to merge 1 commit into
Conversation
… acquire acquirePortalSession() launched chromium, then ran newContext/newPage/ ensureLoggedIn unguarded. If any of those threw (a flaky login, an MFA wall, a nav timeout) the session object that owns close() was never returned, so the just-launched browser leaked. The scheduled runner acquires once per login every tick, so a persistently failing login piled up one zombie headless-Chrome per retry — observed as 200+ orphan chrome procs (~7 GiB) across the non-prod instances, whose NG logins fail (prod's login works, so prod never leaked). Wrap the post-launch steps in try/catch and close() the browser before rethrowing. Harden collect.ts the same way: its own-browser path created the context/page before the try/finally, so a throw there leaked too — move them inside the try. No behavior change on the happy path; 1005 unit tests green.
8a48888 to
ba14188
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
acquirePortalSession()launched Chromium, then rannewContext/newPage/ensureLoggedInunguarded. If any of those threw — a flaky login, an MFAwall, a nav timeout — the
PortalSessionobject that ownsclose()was neverreturned, so the just-launched browser was orphaned.
The scheduled runner acquires one session per login every tick, so a
persistently failing login orphans a headless-Chrome on every retry. In a
real deployment this accumulated 200+ zombie chrome processes (~7 GiB) on
the non-prod instances, whose National-Grid logins fail. (Prod's login works,
so prod never leaked — which is why it went unnoticed.)
collect.tshad the same bug class in its own-browser path: it created thecontext/page before the
try/finally, so a throw there leaked too.Fix
session.ts— wrap every post-launch step intry/catch;close()thebrowser before rethrowing. Happy path unchanged (the returned session's
close()still owns normal teardown).collect.ts— movenewContext/newPageinside thetryso a throwthere reaches the
finallythat closes the own-browser.Validation
1005/1005unit tests pass (docker build --target test).