Skip to content

clear pending session launches when the launched process dies - #18209

Merged
kevinushey merged 1 commit into
mainfrom
bugfix/18208-pending-launch
Jul 13, 2026
Merged

kevinushey merged 1 commit into
mainfrom
bugfix/18208-pending-launch

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

rserver already buffers proxied RPCs across a session restart: sessionRetryProfile retries the session connection every 25ms for up to rsession-proxy-max-wait-secs (default 30s), relaunching the session on the first failed attempt. But that recovery path had a stuck state, diagnosed from the e2e failure on PR #18203:

  1. The first post-suspend RPC's relaunch raced the still-exiting suspended session and its process died, leaving a pendingLaunches_ entry behind.
  2. SessionManager::launchSession treats any pending launch younger than one minute as in-flight, and launchSessionRecovery only attempted a launch on the first recovery pass -- so nothing ever re-attempted the launch. Every request buffered behind the dead launch burned its full 30s wait and failed with jsonrpc error 1 (Unable to connect to service).
  3. The stale entry was only cleared when a failing RPC's error handler called removePendingLaunch, which is why the next request after the failures relaunched successfully.

Changes:

  • SessionManager now records the launched pid on the pending-launch entry (notePendingLaunchPid), and the default launcher registers a ChildProcessTracker exit handler that clears the entry when that process dies before a client connection (removePendingLaunchForPid). The removal is pid-matched so a long-lived session's eventual exit cannot clear a newer pending launch for the same context, and pending launches recorded by custom session launchers (no pid) keep the previous age-based behavior.
  • launchSessionRecovery now re-attempts the launch on subsequent recovery passes (throttled to once per second per request) instead of only the first, so requests already waiting relaunch as soon as the dead launch is cleared. launchSession's pending-entry check remains the dedupe point.

With both pieces, a launch that dies mid-suspend self-heals within about a second instead of stalling every buffered request for 30 seconds.

Testing

  • Added ServerSessionManagerTests.cpp covering pending-launch dedupe, pid-matched removal (dead process clears the entry; unrelated pids and unrecorded pids do not).
  • Full rserver-tests suite passes (39 tests).
  • The e2e-side false-pass that let session_suspend.test.ts wedge on this window was fixed separately in fix waitForSessionRestart marker false-pass during session resume #18207; the suspend/resume e2e tests exercise this path in CI.

Fixes #18208.

rserver buffers RPCs during a session relaunch (sessionRetryProfile polls
the connection every 25ms for up to rsession-proxy-max-wait-secs), but the
recovery path had a stuck state: the relaunch was only attempted on the
first recovery pass, and SessionManager::launchSession treats any pending
launch younger than one minute as in-flight. If the launched process died
before a client connection (e.g. it raced a suspending session's exit),
nothing re-attempted the launch, so every buffered request burned its full
30s wait and failed with "Unable to connect to service".

Track the launched pid on the pending-launch entry and clear the entry
from the process tracker's exit handler when that process dies, and
re-attempt the launch from the recovery function (throttled to once per
second per request) so waiting requests relaunch as soon as the dead
launch is cleared.

Addresses #18208.
@posit-snyk-bot

posit-snyk-bot commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@kevinushey
kevinushey requested a review from jeffvroom July 13, 2026 21:25
@gtritchie gtritchie added this to the 2026.08 (Yellow Yarrow) milestone Jul 13, 2026

@jeffvroom jeffvroom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@github-actions

Copy link
Copy Markdown

RStudio E2E - all platforms

All tests passed!

#################### 100% pass rate

Passed Failed Skipped Flaky
1799 0 76 4
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ desktop-linux 455 0 14 1
✅ desktop-macos 451 0 19 0
✅ desktop-windows 455 0 16 1
✅ server-linux 438 0 27 2
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 48b0ffde5f32e7c726e0af380f8e20326ecbc033 - Run #152

@kevinushey
kevinushey merged commit 578d885 into main Jul 13, 2026
24 checks passed
@kevinushey
kevinushey deleted the bugfix/18208-pending-launch branch July 13, 2026 23:54
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.

rpcs can fail with "unable to connect to service" for 30s+ after session suspend

4 participants