Skip to content

e2e Windows shard consumes the full job timeout when every RStudio launch fails instead of failing fast #18522

Closed

Description

@ronblum

System details

RStudio Edition : Desktop
RStudio Version : built from source at commit 07b27665d27822f1c7a36c609fe00ae81c549f1b
                  (first occurrence) and 6453ef9272bdbc8fff1f8045f873238e3827cec9
                  (second occurrence)
OS Version      : Windows Server 2025 (GitHub Actions windows-2025 hosted runner)
R Version       : 4.5.3

Steps to reproduce the problem

Seen twice on the Windows desktop e2e engine
(os-test-e2e-rstudio-desktop-os-windows-server-2025.yml), shard 4 of 4, in CI
rather than through interactive use. The two runs were built from different
commits, so this isn't a single bad build:

  1. Run the Windows desktop e2e engine.
    • The sandbox warmup launch and the first several test launches all succeed,
      each reaching window.rstudio.ready === true in roughly 4.4 seconds.
  2. Partway through the shard a launch stops connecting, and every launch after
    it fails the same way for the remainder of the job.
    • RStudio processes keep being spawned throughout, with new PIDs each time.
      End-of-job cleanup terminates orphaned rstudio (PID 8996) and
      rsession-utf8 (PID 8372) processes.
  3. launchRStudio retries once (2 attempts, e2e/rstudio/fixtures/desktop.fixture.ts:344-360),
    then throws, failing that test's launch.
  4. The next test's launch fails identically, and so on until the job ends.
    • 138 [launch] attempt failures across roughly 110 minutes, in both runs.
    • No test result is ever recorded: zero passes, zero failures.
  5. The no-output watchdog in e2e/rstudio/scripts/run-with-heartbeat.mjs never
    fires.
    • Its idle timer resets on any child output (resetTimer() is called from
      both the stdout and stderr handlers, lines 102-103), and each failed retry
      writes a console.warn, so a run making no progress still looks alive.
  6. The job runs until GitHub's timeout-minutes: 120 cutoff and is recorded as
    cancelled. Both occurrences ran almost exactly 2 hours.
    • This also holds the workflow's concurrency group. In the first occurrence a
      newer push to the same PR sat queued behind it for about an hour, and an
      explicit gh run cancel did not take effect either -- the job only ended
      at the timeout.

The transition, from the second run. Note that healthy launches take 3 seconds
from cleanup to process start, while the one that first fails takes 18:

21:30:36  Cleaning up any RStudio on port 9867...
21:30:39  Starting RStudio with CDP on port 9867...
21:30:39  RStudio process started (PID: 7316)
21:30:45  [launch-timing] + 4399ms window.rstudio.ready === true
21:30:54  Cleaning up any RStudio on port 9867...
21:30:57  Starting RStudio with CDP on port 9867...
21:30:57  RStudio process started (PID: 1504)
21:31:03  [launch-timing] + 4395ms window.rstudio.ready === true
21:31:19  Cleaning up any RStudio on port 9867...
21:31:22  Starting RStudio with CDP on port 9867...
21:31:22  RStudio process started (PID: 3816)
21:31:29  [launch-timing] + 4657ms window.rstudio.ready === true
21:32:26  Cleaning up any RStudio on port 9867...
21:32:44  Starting RStudio with CDP on port 9867...
21:32:44  RStudio process started (PID: 9380)
21:33:16  [launch] attempt 1/2 failed: Failed to connect to CDP at http://127.0.0.1:9867 within 30000ms: browserType.connectOverCDP: Timeout 5000ms exceeded.
21:33:16  Cleaning up any RStudio on port 9867...

The first failure reports Timeout 5000ms exceeded. Every one after it reports
ECONNREFUSED, and continues doing so for the rest of the job:

21:33:33  RStudio process started (PID: 1160)
21:34:02  RStudio process started (PID: 4708)
21:34:32  [launch] attempt 1/2 failed: Failed to connect to CDP at http://127.0.0.1:9867 within 30000ms: browserType.connectOverCDP: connect ECONNREFUSED 127.0.0.1:9867
21:34:49  RStudio process started (PID: 7944)
21:35:38  RStudio process started (PID: 1376)
21:36:08  [launch] attempt 1/2 failed: Failed to connect to CDP at http://127.0.0.1:9867 within 30000ms: browserType.connectOverCDP: connect ECONNREFUSED 127.0.0.1:9867

and, nearly two hours later, still the same, until the job is cut off:

23:22:04  [launch] attempt 1/2 failed: Failed to connect to CDP at http://127.0.0.1:9867 within 30000ms: browserType.connectOverCDP: connect ECONNREFUSED 127.0.0.1:9867
23:22:21  Terminate orphan process: pid (8996) (rstudio)
23:22:21  Terminate orphan process: pid (8372) (rsession-utf8)

Describe the problem in detail

Once RStudio stops being reachable over CDP partway through a shard, nothing
detects that every subsequent test is failing for the same reason. The
per-launch retry is correctly bounded at 2 attempts, but there is no
shard-level circuit breaker for "N consecutive launches have failed, stop
trying." The heartbeat watchdog was written for this class of problem and does
work -- it caught a genuinely silent hang in the same batch of runs, reporting
run-with-heartbeat: no output for 300s -- treating the run as hung and terminating it -- but it cannot see this shape, because the retry loop's own
logging keeps its idle timer alive. The result is a shard that occupies a
Windows runner for two hours, produces no test signal at all, and blocks other
queued runs in the same concurrency group.

Noted as an open question rather than a diagnosis: it isn't clear why the port
stops accepting connections. Seven launches on port 9867 succeed and then none
do, while RStudio processes continue to spawn without binding it. That could be
RStudio failing to open its remote-debugging port on a later relaunch, or the
harness's between-launch cleanup (Cleaning up any RStudio on port 9867...)
leaving state that prevents rebinding -- the longer 18-second gap on the failing
launch may be a clue. Nothing in the logs distinguishes those, so this report
doesn't assume either, and the request below is only about how the harness
responds.

Describe the behavior you expected

A shard would ideally give up after a small bounded number of consecutive launch
failures and fail red within a few minutes, so that an environment problem
doesn't cost two hours of a Windows runner, surfaces a clear reason in the
report, and doesn't hold the concurrency group against newer runs.

Activity

  1. added
    new
    on Aug 12, 2026
  2. self-assigned this
    on Aug 12, 2026
  3. removed
    new
    on Aug 12, 2026
  4. ronblum commented on Aug 12, 2026

    @ronblum
    ContributorAuthor

    Recurred again on the Windows desktop e2e engine, same CDP-connection-loss pattern: after a restart, RStudio starts but Playwright can't connect to CDP, retries are exhausted, and the next test's launch fails the same way.

    aiting for RStudio process to exit...
    Old RStudio exited (code 0)
    RStudio PIDs after restart: 2708, 5088, 5760, 5816
    New PIDs to kill: 2708, 5088, 5816
    Killed PID 2708
    Killed PID 5088
    Killed PID 5816
    CDP port: 9867
    Cleaning up any RStudio on port 9867...
    [sandbox] this spec's config: D:\a\rstudio\rstudio\pw-sandbox\pw_sandbox_rWJrxf\config_G9brFu
    Starting RStudio with CDP on port 9867...
    RStudio process started (PID: 8596)
    [launch] attempt 1/2 failed: Failed to connect to CDP at http://127.0.0.1:9867 within 30000ms: browserType.connectOverCDP: Timeout 5000ms exceeded.
    CDP port: 9867
    Call log:
    Cleaning up any RStudio on port 9867...
      - <ws preparing> retrieving websocket url from http://127.0.0.1:9867
     -- retrying
    [sandbox] this spec's config: D:\a\rstudio\rstudio\pw-sandbox\pw_sandbox_rWJrxf\config_G9brFu
    Starting RStudio with CDP on port 9867...
    RStudio process started (PID: 384)
      x   12 [desktop-windows] › tests\panes\posit-assistant-chat\uninstall-posit-ai.test.ts:152:7 › Uninstall Posit Assistant - #17322 › Confirm uninstall deletes PAI and restarts @ai @chat @serial @desktop_only (2.0m)
      -   13 [desktop-windows] › tests\panes\posit-assistant-chat\uninstall-posit-ai.test.ts:176:7 › Uninstall Posit Assistant - #17322 › Reinstall Posit Assistant for cleanup @ai @chat @serial @desktop_only
    ◇ injected env (0) from .env.local // tip: ⌘ override existing { override: true }
    CDP port: 9867
    Cleaning up any RStudio on port 9867...
    [sandbox] this spec's config: D:\a\rstudio\rstudio\pw-sandbox\pw_sandbox_rWJrxf\config_6n1q6Q
    Starting RStudio with CDP on port 9867...
    RStudio process started (PID: 4612)
    [launch] attempt 1/2 failed: Failed to connect to CDP at http://127.0.0.1:9867 within 30000ms: browserType.connectOverCDP: connect ECONNREFUSED 127.0.0.1:9867
    Call log:
      - <ws preparing> retrieving websocket url from http://127.0.0.1:9867
    CDP port: 9867
     -- retrying
    Cleaning up any RStudio on port 9867...
    [sandbox] this spec's config: D:\a\rstudio\rstudio\pw-sandbox\pw_sandbox_rWJrxf\config_pdTmKC
    Starting RStudio with CDP on port 9867...
    RStudio process started (PID: 1448)
    [launch] attempt 2/2 failed: Failed to connect to CDP at http://127.0.0.1:9867 within 30000ms: browserType.connectOverCDP: connect ECONNREFUSED 127.0.0.1:9867
    Call log:
      - <ws preparing> retrieving websocket url from http://127.0.0.1:9867
     -- giving up
      x   14 [desktop-windows] › tests\panes\posit-assistant-chat\uninstall-posit-ai.test.ts:99:7 › Uninstall Posit Assistant - #17322 › Uninstall Posit Assistant visible in command palette @ai @chat @serial @desktop_only (retry #1) (0ms)
    

    Unlike the earlier occurrences, these tests resolved to real fail/skip verdicts instead of hanging for the rest of the job.

  5. self-assigned this
    on Aug 12, 2026
  6. kevinushey commented on Aug 12, 2026

    @kevinushey
    Collaborator

    Root cause found -- the open question ("why does the port stop accepting connections?") is answerable, and the trigger is the same in all three occurrences: uninstall-posit-ai.test.ts test 4, which uninstalls Posit Assistant and restarts RStudio.

    The restart instance is spawned by the dying Electron main (ApplicationLaunch.launchRStudio), and on Windows Node's spawn creates children with bInheritHandles=TRUE -- so the restarted, non-CDP instance silently inherits the old main's CDP listen socket handle. Normally harmless, because relaunchAfterRestart kills the whole restarted tree. But its "PIDs before restart" snapshot is taken after the Yes click, racing the restart spawn: on a loaded runner the restarted main is already up, lands in the "before" set, and the before/after diff spares it. Both 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 end-of-job cleanup terminates two hours later.

    The spared orphan keeps the port in LISTEN with nobody accepting, which explains every observed detail:

    • first failure is Timeout 5000ms exceeded (connects queue in the ~10-entry accept backlog and the HTTP request never gets answered; one 30s launch loop makes ~6 attempts, under the limit);
    • everything after is ECONNREFUSED (backlog full -> Windows RSTs new SYNs);
    • the 18s/17s gaps between "Cleaning up" and "Starting" on every post-transition launch are the port-wait loop's 15s ceiling: Get-NetTCPConnection sees the zombie listener, but its OwningProcess is the dead creator PID (socket ownership is recorded at creation, not per handle-holder), so Stop-Process is a silent no-op;
    • each new Electron gets WSAEADDRINUSE on the port and continues without DevTools, so nothing ever listens properly again.

    The third occurrence recovering into real fail/skip verdicts is consistent with the spared PID there (5760) being a recycled-PID helper rather than the main, so the inherited handle died when the main was killed.

    Fixes in #18538: the relaunch kill now diffs against a caller-provided snapshot taken before the restart is triggered, keyed on (pid, start time); a launch now fails immediately with the real reason when a LISTEN socket on the CDP port survives cleanup; and a consecutive-launch-failure circuit breaker (default 3, PW_LAUNCH_FAILURE_STREAK_LIMIT) makes a broken shard fail red in minutes instead of running out the 2h job timeout behind the heartbeat watchdog.

  7. ronblum commented on Aug 13, 2026

    @ronblum
    ContributorAuthor

    Another occurrence, on an unrelated PR (bugfix/environment-restart-connection-error): https://github.com/rstudio/rstudio/actions/runs/31639429483/job/94271140723

    139 "Failed to connect to CDP" failures, job cancelled rather than completing. Confirms this isn't tied to any particular PR's changes.

  8. removed their assignment
    on Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions