Skip to content

e2e: fix relaunch pid-diff race; fail fast when launches keep failing - #18538

Merged
kevinushey merged 1 commit into
mainfrom
bugfix/18522-e2e-launch-fail-fast
Aug 13, 2026
Merged

kevinushey merged 1 commit into
mainfrom
bugfix/18522-e2e-launch-fail-fast

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Addresses #18522.

Root cause

All three occurrences transition at uninstall-posit-ai.test.ts test 4, which uninstalls Posit Assistant and triggers doRestart(). Two things combine:

  1. The restart instance is spawned by the dying Electron main (ApplicationLaunch.launchRStudio in src/node/desktop/src/main/application-launch.ts) via Node spawn, which on Windows creates children with bInheritHandles=TRUE -- so the restarted (non-CDP) instance inherits the old main's CDP listen socket handle.

  2. relaunchAfterRestart snapshotted "PIDs before restart" after the test clicked Yes, racing that spawn. On a loaded runner the restarted main is already running when PowerShell samples the process list, lands in the "before" set, and is spared by the before/after diff -- only its helper children get killed.

Both failing job logs show the signature: one PID present in both snapshots (run 1: 2748, run 2: 8996), and that exact PID plus an rsession-utf8 are the orphan pair the end-of-job cleanup terminates two hours later.

The spared orphan keeps the port in LISTEN with nobody accepting: the first failed launch reports Timeout 5000ms exceeded (connects queue in the ~10-entry accept backlog), every later one ECONNREFUSED (backlog full -> RST). The per-launch cleanup can't clear it -- the TCP table attributes the socket to its (dead) creator PID, so Stop-Process is a no-op and every launch stalls the full 15s port-wait -- and each new Electron gets WSAEADDRINUSE on the port and silently continues without DevTools. Hence 138 failed launches across ~110 minutes with zero test results.

Fixes

  • relaunchAfterRestart kill targeting: callers must now pass a snapshot taken with snapshotRStudioProcesses() before triggering the restart, and the snapshot keys on (pid, start time) so a PID recycled by Windows can't masquerade as a pre-existing process. Sparing genuinely pre-existing instances (a developer's own RStudio) still works.
  • Poisoned-port fail-fast: if a LISTEN socket on the worker's CDP port survives cleanup and the 15s wait, the launch now throws immediately with the real reason instead of spawning an RStudio that can never bind the port.
  • Launch circuit breaker (the behavior this issue asked for): launchRStudio tracks the consecutive-failure streak in a sandbox file (worker restarts don't reset it) and refuses further launches once it crosses PW_LAUNCH_FAILURE_STREAK_LIMIT (default 3). A broken shard now fails red in a few minutes instead of holding the runner and its concurrency group for the full 2h timeout.

Verification

  • npm run typecheck passes.
  • snapshotRStudioProcesses() verified on macOS against a stand-in RStudio process (pid + lstart captured correctly).
  • Circuit breaker exercised via a scratch harness: streak increments 1 -> 2 -> 3 across failed launches, opens at 3 (fourth call refuses without attempting), file resets on success.
  • tests/harness/client_exceptions.test.ts (4 tests) passes on macOS through the modified launch path.
  • The Windows-specific pieces (PowerShell snapshot, unclearable-listener fail-fast) follow the file's existing PowerShell patterns but need a Windows desktop e2e run to confirm; the uninstall suite also needs PAI credentials, so it only runs fully on CI.

Three related fixes for the Windows shard that burned its full 2h job
timeout after every RStudio launch stopped connecting over CDP:

- relaunchAfterRestart now requires the caller to snapshot running
  RStudio processes BEFORE triggering the restart, keyed on
  (pid, start time). The restart instance is spawned by the dying
  Electron main, so the old post-click snapshot raced that spawn and
  could classify the new instance as pre-existing, sparing it. The
  spared orphan holds an inherited handle to the old main's CDP listen
  socket, keeping the port in LISTEN (unkillable via its owning PID,
  unbindable by every later launch) for the rest of the shard.

- launchRStudioOnce now fails immediately, with the real reason, when
  a LISTEN socket on the CDP port survives cleanup, instead of
  spawning an RStudio that can never bind it.

- launchRStudio now keeps a consecutive-failure streak in a sandbox
  file and refuses to launch once it crosses a threshold (default 3,
  PW_LAUNCH_FAILURE_STREAK_LIMIT to tune), so a broken environment
  fails the shard red in minutes instead of running out the job
  timeout behind the heartbeat watchdog.

Addresses #18522.
@github-actions

Copy link
Copy Markdown

RStudio E2E - all platforms

3 test(s) failed

###################- 99% pass rate

Passed Failed Skipped Flaky
2071 3 126 6
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 1 0 8 0
✅ desktop-linux 584 0 31 1
✅ desktop-macos 590 0 26 1
❌ desktop-windows 586 2 31 3
❌ server-linux 291 1 22 1
✅ setup 19 0 8 0
View / download the full report

View report online -- opens in the browser, no download needed. Available for 14 days.

Download playwright-report.zip -- extract and open index.html

Includes screenshots, traces, and step-by-step details for every test. Expires in 15 days.


All platforms - commit c35cce5fcc5e537e376c9f95238a38f61e91a414 - Run #574

@kevinushey
kevinushey merged commit 1edcd72 into main Aug 13, 2026
21 of 27 checks passed
@kevinushey
kevinushey deleted the bugfix/18522-e2e-launch-fail-fast branch August 13, 2026 18:57

This branch had an error being deployed

1 failed deployment
e2e-playwright — c35cce5f Deployed Aug 12, 2026 by kevinushey via windows / e2e-desktop-windows (4) #574
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