Repository navigation
Fix Local.stop() calling its callback twice on a kill error - #193
Draft
pranay-v29 wants to merge 1 commit into
Draft
pranay-v29 wants to merge 1 commit into
pranay-v29 wants to merge 1 commit into
Conversation
The error branch in stop() had no return, so a failed kill called back with a LocalError and then again with no error. Since 1.5.11 switched killAllProcesses to tree-kill, kill errors reach that branch. stop() now calls back exactly once. A kill error is reported only while the process is still running; if it has already exited (a repeat stop(), or taskkill reporting the pid as not found on Windows) the tunnel is stopped and stop() reports success. On success it clears pid and isProcessRunning, so a second stop() is a no-op. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
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
Local.stop()has noreturnafter its error callback:When the kill fails, the caller gets
callback(LocalError)and thencallback(). Callers that pass a plain callback run both their error path and their success path; a mochadonefails with "done() called multiple times". Callers that wrapstop()in a Promise are unaffected because only the first call settles it.The missing
returnis old, but it became reachable in 1.5.11, whenkillAllProcessesmoved from ps-tree (which only ever called back with no error) to tree-kill (which passes kill errors through). 1.5.11 through 1.5.17 are affected. tree-kill itself calls back once, so the second call comes only fromLocal.js.Fix
stop()now calls back exactly once:LocalErroronly.pidis kept so the caller can retry.stop()or a binary that already exited; on Windows, tree-kill runstaskkill, which reports any non-zero exit as an error. Liveness is checked with the existingis-runningdependency, so no platform- or locale-specific error parsing is needed.pidandisProcessRunning, so a secondstop()returns immediately without trying to kill again. Earlier releases (up to 1.5.10) also resetisProcessRunningon stop; clearingpidis new.Only adding the
returnwould have turned the stray second success into a lost success for callers written asstop(err => { if (err) return; next(); })when stopping an already-exited process, so the already-exited case is handled explicitly.Tests
New
test/local_stop_callback.jsstubskillAllProcesses, so it needs no binary or access key and signals no process. It covers: kill error while running, kill error after exit, kill success, no pid, and stopping twice.masterlib/Local.js: 4 failing (the no-pid case already behaved correctly).eslint lib/* index.jspasses, and the other offline test files (local_start_output_handling,local_binary_busy_download,proxy_auth_download) still pass: 30 passing in total.test/local.js, which needs an access key and starts the real binary. Not tested on Windows.🤖 Generated with Claude Code