Skip to content

fix rserver double session launch that leaks an orphaned rsession - #18573

Merged
kevinushey merged 4 commits into
mainfrom
bugfix/rserver-double-session-launch
Aug 15, 2026
Merged

kevinushey merged 4 commits into
mainfrom
bugfix/rserver-double-session-launch

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Fixes #18572. Fixes #18571.

An R session restart on RStudio Server could leak an orphaned rsession that runs forever. Root-caused from the rserver debug log of e2e run 31839732347: after the old session acked suspend_for_restart and exited, rserver launched two replacements one second apart. An RPC still in flight to the exiting session died with EOF, and handleRpcError unconditionally removed the pending-launch record of the first replacement (spawned 37 ms earlier); the retrying /rpc/ping's one-second launch throttle then spawned a second one. Both booted, the second re-bound the session stream socket, and the first became unreachable -- never contacted, never told to exit, holding the project source-database lock (surfacing the "previous R session terminated abnormally" dialog) and the Posit Assistant install lock, and reacting to shared user-prefs changes indefinitely.

Two fixes:

  • ServerSessionManager::removePendingLaunch no longer erases a pending launch on the request-error paths while the launched process is still alive: a request failing for the context says nothing about the health of a separately launched, still-booting session. The existing safety nets still clear the entry -- the SIGCHLD process tracker (rpcs can fail with "unable to connect to service" for 30s+ after session suspend #18208) when the pid dies, and launchSession's one-minute window otherwise. Custom session launchers never record a pid and keep the old clear-on-error behavior. (Also moves core::system::isProcessRunning out of the Linux-only branch of PosixSystem.cpp; it is plain POSIX, was declared unconditionally in the header, and failed to link on macOS.)
  • The Posit Assistant install lock owner id is now unique per process (<session-id>-<uuid>). It was the bare session id, which is stable across relaunches, so an orphaned predecessor held a live lock under its replacement's own name and every chat_start_backend in the replacement failed with a spurious, never-clearing "A Posit Assistant update is in progress." With the per-process id, even an orphan can only make mutations (update/uninstall) refuse -- correctly, since the install genuinely is in use -- while backend starts coexist, which is the supported multi-session steady state.

Follow-ups noted on #18572 and deliberately not included: the success path (handleProxyResponse) has a much narrower variant of the same race, and an rsession could self-detect a supplanted stream socket and exit.

Verification:

  • New tests: SessionManagerTest.RequestErrorKeepsPendingLaunchOfLiveProcess, RequestErrorClearsPendingLaunchOfDeadProcess, RequestErrorClearsPendingLaunchWithoutRecordedPid; ChatInstallLock.SameOwnerIdCollidesWithLivePredecessor.
  • rstudio-tests --scope rsession: 418/418 pass. --scope rserver: all SessionManagerTest and proxy tests pass (the SqliteDBActiveSessionStorageTest failures are environmental on this machine and identical on main's build).

An error on a request still in flight to an exiting session no longer
erases the pending-launch record of its freshly spawned replacement.
Erasing it let the next connection-retry recovery pass launch a second
replacement one second later; both booted, the second re-bound the
session stream socket, and the first became an unreachable orphan that
was never told to exit -- still holding the project source-database
lock and the Posit Assistant install lock.

Also moves core::system::isProcessRunning out of the Linux-only branch
of PosixSystem.cpp: it is plain POSIX and was declared unconditionally
in the header, but failed to link on macOS.

Addresses #18572.
The in-use lock file was named by activeSession().id(), which is stable
across session relaunches, so an orphaned predecessor rsession held a
live lock under its replacement's own name and every chat_start_backend
in the replacement failed with a spurious 'A Posit Assistant update is
in progress'. The owner id is now '<session-id>-<uuid>'.

Addresses #18571.
@kevinushey kevinushey added this to the 2026.09 (Autumn Hawkbit) milestone Aug 14, 2026
@kevinushey
kevinushey merged commit bc91c25 into main Aug 15, 2026
1 check passed
@kevinushey
kevinushey deleted the bugfix/rserver-double-session-launch branch August 15, 2026 00:22
@github-actions

Copy link
Copy Markdown

RStudio E2E - all platforms

1 test(s) failed

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

Passed Failed Skipped Flaky
2382 1 152 2
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 591 0 31 1
✅ desktop-macos 598 0 26 0
❌ desktop-windows 596 1 31 1
✅ server-linux 569 0 44 0
✅ setup 26 0 10 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 2c14f6e026d5a03ed2aa3816ec795a8c936fd449 - Run #626

kevinushey added a commit that referenced this pull request Aug 18, 2026
kill(pid, 0) fails with EPERM when the probed process exists but is
owned by another user -- exactly what rserver's privilege-dropped
request threads see when probing a live rsession on a root-launched
multi-user server. The liveness guard from #18573 read that as "not
running" and erased the pending-launch record on request errors, so
the #18572 double-launch stayed reproducible in precisely the
deployment class it targets (dev and e2e servers share a uid with
their sessions and were unaffected). Only ESRCH proves absence; count
EPERM as alive.

Addresses #18572.

This branch was previously deployed

1 inactive deployment
e2e-playwright — 2c14f6e0 Deployed Aug 15, 2026 by kevinushey via linux-desktop / E2E (ubuntu-24-x86_64) #626
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant