Skip to content

Fix Local.stop() calling its callback twice on a kill error - #193

Draft
pranay-v29 wants to merge 1 commit into
masterfrom
fix/stop-single-callback
Draft

pranay-v29 wants to merge 1 commit into
masterfrom
fix/stop-single-callback

Conversation

@pranay-v29

Copy link
Copy Markdown
Collaborator

Problem

Local.stop() has no return after its error callback:

this.killAllProcesses(function(error){
  if(error) callback(new LocalError(error.toString()));
  callback();   // always runs
});

When the kill fails, the caller gets callback(LocalError) and then callback(). Callers that pass a plain callback run both their error path and their success path; a mocha done fails with "done() called multiple times". Callers that wrap stop() in a Promise are unaffected because only the first call settles it.

The missing return is old, but it became reachable in 1.5.11, when killAllProcesses moved 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 from Local.js.

Fix

stop() now calls back exactly once:

  • Kill error, process still running: calls back with the LocalError only. pid is kept so the caller can retry.
  • Kill error, process already exited: calls back with no error. This covers a repeat stop() or a binary that already exited; on Windows, tree-kill runs taskkill, which reports any non-zero exit as an error. Liveness is checked with the existing is-running dependency, so no platform- or locale-specific error parsing is needed.
  • Kill success: calls back with no error and clears pid and isProcessRunning, so a second stop() returns immediately without trying to kill again. Earlier releases (up to 1.5.10) also reset isProcessRunning on stop; clearing pid is new.

Only adding the return would have turned the stray second success into a lost success for callers written as stop(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.js stubs killAllProcesses, 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.

  • With the fix: 5 passing.
  • Against the current master lib/Local.js: 4 failing (the no-pid case already behaved correctly).
  • eslint lib/* index.js passes, and the other offline test files (local_start_output_handling, local_binary_busy_download, proxy_auth_download) still pass: 30 passing in total.
  • Not run: test/local.js, which needs an access key and starts the real binary. Not tested on Windows.

🤖 Generated with Claude Code

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>
@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto (fallback from Default branch)
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited), Workspace UI (inherited); Enforced overrides: Organization
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: 778b274f-0a4c-4477-9e42-28f01c5e1074

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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