Repository navigation
fix(browser): drain DevTools relay calls before session teardown - #466
Merged
Merged
Conversation
Each forwarded tools/call now holds an agent permit until the child answers it, so session teardown drains relay calls before it stops Chrome. While a call is unanswered the relay watches the session. Closed input stops the child, releases the permits and answers each call with the session-ended error. A human lease releases the permits at once so the takeover drain succeeds. Refs #454
When teardown closed input during a call, the relay stopped its child and answered the call, but its input stayed open with nothing reading it. The process lived on, and a later call waited for its client timeout. The relay now releases its input, so it exits and the client sees it close.
Permits were released only after the relay's output settled. A client that stopped reading could hold them through the whole teardown drain, and teardown then failed. Once the child exits, no call can reach Chrome, so the relay releases its permits then. Each close now waits for every release already started. A new test pins that a response the child sends while it stops is forwarded with no session-ended answer.
Only the closed-input shutdown released the relay's input. When the child exited with a code, or a pump failed, the client's still open input kept the relay process alive, and a later call waited for its client timeout. The relay now releases its input on every exit, after every path has settled the input pump.
The watcher's last check runs after the last answer. When teardown closed input inside that window, the relay stopped its child and exited with nothing in flight, so later calls failed with "Not connected" instead of the session-ended error. That check now ends the relay only while a call is unanswered.
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.
Closes #454
Each DevTools relay
tools/callnow holds an agent permit until the upstream child answers it, so session teardown drains relay calls before it stops Chrome. While a call is unanswered, the relay checks the session about every 100 ms. When teardown closes input, the relay stops its child, releases the permits, answers each unanswered call with the session-ended error (-32051) and exits. A relay with no call unanswered stays up as before, and a later call gets the same error. A human takeover releases the permits it covers at once, so its 5 s drain still succeeds, and the running call can still finish. SECURITY.md describes the drain and the window that remains during takeover.A call the client cancels gets no response, but the child may still run it. It keeps its permit until the relay ends, input closes or a lease appears.
The third checklist item, moving CDP to
--remote-debugging-pipe, changes how Chrome starts and how the upstream child connects. It is tracked in #459.Traceability
tools/calluntil its responsemainshows 0 permits while a call runs~/.pickforge/investigations/454-relay/before-probe.log,r3-sol/after-1.logtoafter-3.logsession destroyqa/qa-repro.mjs) with one held call and one queued call acrosssession destroymainand this branchmain: Chrome exits first, and the queued call getsECONNREFUSEDon the freed port. This branch: the child exits at 68 ms, the relay at 84 ms and Chrome at 135 ms, and both calls get -32051~/.pickforge/investigations/454-relay/qa/run-main.log,qa/run-branch-r4.log--remote-debugging-pipe~/.pickforge/investigations/454-relay/r3-sol/before.log,r3-sol/sol-lease-repro.logmainit stays~/.pickforge/investigations/454-relay/qa/later-main.log,qa/later-branch-r4.logpackages/cli/test/devtools-real.test.tswith real Chrome; an idle real-Chrome journeymain; the real-Chrome test passes 4 of 4 and failed on 9ff9fe0~/.pickforge/investigations/454-relay/qa/idle-main.log,qa/idle-branch-r4.log,r2-fable/devtools-real-head.log,r3-sol/devtools-real.logfull-suite.sh~/.pickforge/investigations/454-relay/full/pickcheck check --base origin/main --fail-on new,worsened,unmatched; gitleaks on the branch commits~/.pickforge/investigations/454-relay/pickcheck-final.json,gitleaks-final.logReview
Council of Sol and Fable. The Kimi seat did not run: its provider hit a usage limit during this batch.
The lead's QA also found two defects, both fixed with tests. After teardown ended its calls, the relay stayed up while its client held stdin open; fixed in 135b25b. The real-Chrome test failed when the last watcher check ran after the last answer and ended an idle relay; fixed in 5b68cb5.