Skip to content

wait for a slow restart to answer before giving up on it - #18872

Merged
kevinushey merged 3 commits into
mainfrom
bugfix/restart-completion-ping-budget
Sep 18, 2026
Merged

kevinushey merged 3 commits into
mainfrom
bugfix/restart-completion-ping-budget

Conversation

@kevinushey

@kevinushey kevinushey commented Sep 17, 2026 •

Copy link
Copy Markdown
Collaborator

Intent

SessionOpener.sendPing waits for a restarted session to answer a ping, and fires ConsoleRestartRCompletedEvent when it does. Two things made it give up while the session was still on its way back:

  • It ticked every 200ms and spent one of its 50 retries on every tick, including ticks where a ping was already in flight and nothing was sent. The budget was therefore a flat ~10.2s of wall clock however many pings were actually attempted. On exhaustion the loop marked itself completed, so the ping that answered a moment later was discarded by the completed_ guard in onSuccess and the event never fired. A ping can legitimately sit unanswered for much longer than 10s: rserver holds an RPC aimed at a session it is still relaunching (rsession-proxy-max-wait-secs, default 30s), and the new session then has to restore the workspace and search path.
  • A failed ping ended the wait outright, so the retry that would have reached the new session was never sent. That half dates to ensure sendPing onCompleted fires exactly once #17906, which correctly made onCompleted fire exactly once but also made the first failure terminal, leaving maxRetries unused.

Either way the restart looked fine -- onCompleted ran, the progress indicator was dismissed, RESTART_COMPLETED fired -- while everything hanging off ConsoleRestartRCompletedEvent was silently skipped: Shell.onRestartRCompleted leaves the console unfocused with a stale prompt, and ConsoleTabPanel never refreshes the Console pane's interpreter version.

Approach

Budget the wait in wall-clock time (60s) rather than in ticks, wait for an outstanding ping instead of spending the budget on ticks that send nothing, keep pinging after a failure, and announce the restart whenever a ping answers -- including one that answers within 5s after the wait timed out, since an answer means R really is back; later than that, refocusing the console would pull the user away from whatever they moved on to. onCompleted still runs exactly once, on an answered ping or on timeout.

Tests

SessionOpenerTests covers both halves directly; each test fails against the current implementation:

  • a failed ping is retried, and the ping that answers announces the restart and completes the wait once
  • an outstanding ping is awaited rather than piled on, and a response that arrives after the timeout still announces the restart

It also covers the bound on that late announcement: an answer that arrives past the 5s grace period does not announce the restart.

e2e/rstudio/tests/panes/console/interpreter_version.test.ts (added in #18858) is where this surfaced. It restarts R twice on RStudio Server, where each restart takes 9-11s -- straddling the 10.2s budget -- and has been failing on essentially every linux-server run, e.g. run 35259099463, with the second restart's ping answered at 10.9s and its success discarded. It held the completion ping until the session was ready to work around the related failure case; that workaround is what pushed the wait past its budget, and it is removed here.

Verified locally: ant unittest (600 tests) and the interpreter-version spec on desktop. The Server case is covered by this PR's own CI.

Fixes #18870.

SessionOpener.sendPing ticked every 200ms and spent one of its 50 retries
on every tick, including ticks where a ping was already in flight and
nothing was sent. The budget was therefore ~10.2s of wall clock however
many pings were actually attempted, and when it ran out the loop marked
itself completed -- so the ping that did answer a moment later was
discarded by the completed_ guard and ConsoleRestartRCompletedEvent never
fired. A ping can stay unanswered for much longer than that: rserver
holds an RPC aimed at a session it is still relaunching, and the new
session then has to restore the workspace before it services RPCs.

A failed ping ended the wait outright too, so the retry that would have
reached the new session was never sent. That half dates to #17906, which
made onCompleted fire exactly once but also made the first failure
terminal, leaving maxRetries unused.

Budget the wait in wall-clock time instead (60s), wait for an outstanding
ping rather than spending the budget on ticks that send nothing, retry
after a failure, and announce the restart whenever a ping answers -- even
if the wait already timed out, since an answer means R really is back.
onCompleted still runs exactly once.

Without the event, Shell leaves the console unfocused with a stale prompt
and the Console pane keeps showing the previous R version. The e2e test
added in #18858 hit this on Server, where a restart takes 9-11s; it no
longer needs to hold the completion ping to keep the event alive.

Addresses #18870.
@kevinushey kevinushey added this to the 2026.10 (Blue Mistflower) milestone Sep 17, 2026
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:22 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:22 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:25 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:25 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:29 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:29 — with GitHub Actions Active

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No blocking issues. 2 follow-up, 1 nit.

🟠 is real but not merge-blocking — either address it here or open an issue to do so later. 🟡 is optional.

  • 🟠 src/gwt/src/org/rstudio/studio/client/workbench/model/SessionOpener.java:263 — a restart that never comes back now blocks for the full 60s
  • 🟠 src/gwt/src/org/rstudio/studio/client/workbench/model/SessionOpener.java:257 — a post-timeout ping answer can steal console focus arbitrarily late
  • 🟡 src/gwt/src/org/rstudio/studio/client/workbench/model/SessionOpener.java:277 — restartAnnounced_ guard is unreachable

}

@Override
protected void onFailure()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟠 A restart whose session never comes back now keeps "Restarting R..." on screen for the full 60s instead of ending on the first failure.

Keep a terminal condition for a run of consecutive failures (e.g. give up after N in a row, or after a shorter budget when no ping has ever been answered).

Why

On Desktop, a Restart R where the new rsession fails to launch makes every ping fail immediately with a connection error. onFailure now just clears pingInFlight_ and returns, so the loop re-pings every 200ms for the whole 60s -- roughly 300 failed RPCs, each one logged by VoidServerRequestCallback.onError.

For that whole minute ApplicationQuit.suspendingAndRestarting_ is still true, so Application.onClientDisconnected early-returns and the "Application disconnected" screen never appears; WorkbenchContext.isRestartInProgress_ also stays set, suppressing errors from other RPCs. The user gets a minute of "Restarting R..." with no indication anything went wrong, where the previous code released in ~200ms.

I agree the old first-failure-is-terminal behaviour was wrong for the early ping that lands while the old session is shutting down -- the point is only that there is now no terminal condition at all on the failure path.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think the failure path needs its own terminal condition. For a Desktop relaunch that fails: if the spawn fails, launchNextSession errors and Electron quits the window; if the process starts and dies, the pending-quit flag was already consumed by the first exit, so Electron reports it as a crash -- notifyRCrashed → SuicideEvent → cleanupWorkbench() disconnects the RPC layer and shows the "R Session Aborted" popup. After that sendRequest drops the ping without calling back, so the loop stops pinging and idles to the timeout behind the popup; there's no stream of failed RPCs. On Server, rserver already retries behind each ping (every 25ms, relaunching at most once a second, for up to rsession-proxy-max-wait-secs), so a connection failure only comes back after ~30s. What's left is a Desktop session that's alive but hasn't opened its listener yet -- the one case where it may well still answer, and where a cap would reintroduce #18870. So I'd rather keep failures non-terminal and let the 60s timeout bound the wait.

// ourselves completed so onCompleted fires only once
completed_ = true;
// the session answered, so the restart really is done --
// announce it even if the loop above already timed out

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟠 Nothing bounds how late a post-timeout ping may answer, so the console can grab focus long after the restart was declared finished.

Ignore a response that arrives more than a short grace period past the timeout, rather than accepting one at any later point.

Why

Announcing on a late answer makes sense, but the loop returns false at the timeout, so there is no upper bound on how much later the outstanding ping may resolve. By then onCompleted has run, RESTART_COMPLETED has cleared restartInProgress_ and suspendingAndRestarting_, and the user has moved on.

When that ping finally answers, Shell.onRestartRCompleted fires SendToConsoleEvent("", true) and calls focus() -- pulling focus to the Console mid-edit in the source editor, minutes after the restart appeared to finish.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. 430cd1e only announces a post-timeout answer if it arrives within 5s of the timeout; anything later is dropped. Covered by testAnswerPastTheGracePeriodIsIgnored.


private void announceRestartCompleted()
{
if (restartAnnounced_)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟡 restartAnnounced_ can never be true when this check runs, so the guard is dead code.

Drop the field and fire ConsoleRestartRCompletedEvent directly in onSuccess.

Why

pingInFlight_ keeps exactly one ping outstanding at a time, and onSuccess calls complete() alongside announceRestartCompleted(), which stops the loop. So onSuccess runs at most once per sendPing call and the method can never be re-entered.

Minor, but the guard reads as protection against a re-entrancy hazard that the surrounding code already rules out.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right -- with one ping in flight and complete() on success, onSuccess runs at most once. Dropped the field and the helper; the event now fires inline (430cd1e).

@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:37 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:37 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:37 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:37 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:37 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 17, 2026 21:37 — with GitHub Actions Active
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

RStudio E2E - all platforms

1 test(s) failed

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

Passed Failed Skipped Flaky
3054 1 196 3
Platform ✅ Passed ❌ Failed ⚠️ Skipped 🔁 Flaky
✅ auth-teardown 2 0 10 0
✅ desktop-linux 771 0 38 0
✅ desktop-macos 768 0 42 0
✅ desktop-windows 772 0 42 1
❌ server-linux 713 1 44 2
✅ setup 28 0 20 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 8a5a5e47ee7ce19a519927accf5dbfb52a1648f4 - Run #1084

kevinushey and others added 2 commits September 17, 2026 21:25
A ping that answers after the timeout still announces the restart, but
only within a 5s grace period: announcing refocuses the console, which
would otherwise pull the user away arbitrarily late.

Also drop the restartAnnounced_ guard, which one-ping-at-a-time already
made unreachable.

Addresses #18870.
@kevinushey
kevinushey merged commit 40b8abe into main Sep 18, 2026
1 of 5 checks passed
@kevinushey
kevinushey deleted the bugfix/restart-completion-ping-budget branch September 18, 2026 16:07
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:21 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:21 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:26 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:30 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:30 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:34 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:34 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:34 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:34 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:34 — with GitHub Actions Active
@kevinushey
kevinushey deployed to e2e-playwright September 18, 2026 16:34 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
e2e-playwright — 8a5a5e47 Deployed Sep 18, 2026 by kevinushey via windows / e2e-desktop-windows (1) #1084
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.

Restart R silently skips its completion event when the session takes more than ~10s to answer

2 participants