Repository navigation
wait for a slow restart to answer before giving up on it - #18872
Conversation
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.
gtritchie
left a comment
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
🟠 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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
🟠 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.
There was a problem hiding this comment.
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_) |
There was a problem hiding this comment.
🟡 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.
There was a problem hiding this comment.
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).
RStudio E2E - all platforms1 test(s) failed
View / download the full reportView report online -- opens in the browser, no download needed. Available for 14 days. Download playwright-report.zip -- extract and open
All platforms - commit |
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.
Intent
SessionOpener.sendPingwaits for a restarted session to answer a ping, and firesConsoleRestartRCompletedEventwhen it does. Two things made it give up while the session was still on its way back:completed_guard inonSuccessand 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.onCompletedfire exactly once but also made the first failure terminal, leavingmaxRetriesunused.Either way the restart looked fine --
onCompletedran, the progress indicator was dismissed,RESTART_COMPLETEDfired -- while everything hanging offConsoleRestartRCompletedEventwas silently skipped:Shell.onRestartRCompletedleaves the console unfocused with a stale prompt, andConsoleTabPanelnever 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.
onCompletedstill runs exactly once, on an answered ping or on timeout.Tests
SessionOpenerTestscovers both halves directly; each test fails against the current implementation: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.