Repository navigation
revive client event stream after session restart - #18341
Conversation
After a session suspend/restart on RStudio Server, the client's get_events long-poll fails while the session is down and RemoteServerEventListener gives up after a short retry budget, remaining stopped indefinitely: successful RPCs only call ensureEvents() when their response reports events pending, so the client stays deaf to events (including DeferredInitCompletedEvent, which triggers 'Restart R and Run All Chunks') until some later RPC happens to report pending events. Schedule a slow-cadence (5s) revival attempt whenever the listener stops due to errors, cancelled by stop() so deliberate stops (hidden multi-session tabs, window close) are unaffected. Also harden the e2e waits that sit downstream of this delivery path so they comfortably cover a slow-but-successful restart on binaries without the fix. Addresses #18340
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
The extended waits could not have rescued a pre-fix binary anyway (a dead event stream is not woken by the passage of time, only by an RPC that reports pending events), and with the revival fix in place the original 60s budgets have ample margin. Keeping them tight means a regression of #18340 fails the always-on rmarkdown spec loudly instead of being masked. Addresses #18340
Defense-in-depth around the revival fix: - reset listenErrorCount_ when a poll succeeds, so the quick-retry budget applies per incident rather than over the lifetime of the page (previously six transient errors spread over hours would send the next incident straight to the stopped state) - route the 500ms quick retries through the guarded revival timer, so they are cancelled by stop() (deliberate stops can no longer be overridden by an in-flight retry) and observe the same sessionWasQuit_ / isDisconnected guards - log a breadcrumb when a revival attempt fires, so event delivery gaps are diagnosable from the browser console Addresses #18340
RStudio E2E - all platformsAll tests passed!
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 |
Code review findingsActionable items from an automated multi-agent review of the event-stream revival change. Line numbers refer to the PR head ( Important
Suggestions
|
- drop the listenErrorCount_ reset in the give-up branch so a prolonged non-UNAVAILABLE outage settles into the slow revival cadence instead of cycling back into quick-retry bursts (the reset now lives on the successful poll) - log the revival breadcrumb once when the listener first stops due to errors, gated on a flag cleared by the successful poll, and include the error code and attempt count (no longer logs on every 5s revival tick) - route retryHandler.onError through scheduleRevival so a failed get_events recovery no longer leaves an idle client permanently deaf, with a breadcrumb - refresh the scheduleRevival doc comment and the throttling comment to describe both revival paths accurately
Fixes #18340.
Problem
On RStudio Server, after a session restart the client can stop receiving events until the user's next action. See #18340 for the full mechanism and CI-run timeline; in short:
suspend_for_restarttakes the session down; theget_eventslong-poll errors (rserver maps a dead session socket toUnavailable, or a bare 503 surfaced as a transmission error). Events requests never initiate session launches, so polling alone cannot bring the session back.RemoteServerEventListener.onErrorstops the listener: immediately forUNAVAILABLE, or after at most 5 retries at 500ms otherwise.ensureListeningForEvents(), but its boundedensureListening(10)burst (2.5s) typically loses the race against the session relaunch that the same RPC triggers; RPC responses only callensureEvents()when they report"ep": "true". A client passively waiting for console output sends no RPCs, so nothing ever revives the stream -- including delivery ofDeferredInitCompletedEvent, which is what runs the queued chunks after "Restart R and Run All Chunks".Fix
RemoteServerEventListenernow schedules a slow-cadence (5s) revival attempt whenever it stops due to errors (both theUNAVAILABLEpath and the retry-budget-exhausted path), making revival independent of further user/RPC activity. The revival timer:stop(), so deliberate stops -- hidden multi-session tabs (ApplicationVisibility), window close -- are not overridden;isListening_/sessionWasQuit_/isDisconnected()before starting, so it no-ops after quit/disconnect or ifensureListening/ensureEventsalready restarted the listener;Unavailableto the (cheap) 5s probes until a real RPC relaunches it.This is the "another way to restart the listener (perhaps a global timer that checks for isListening every few seconds)" already anticipated by the comment in the listener's constructor.
Defense-in-depth hardening in the same area:
listenErrorCount_now resets when a poll succeeds. It was previously only reset when the give-up branch ran, making the 5-retry budget a lifetime budget: a tab that had absorbed six transient errors over hours would skip the quick retries entirely on the next incident.Timerinstances, sostop()cancels them (an in-flight retry can no longer override a deliberate stop) and they observe thesessionWasQuit_/isDisconnected()guards.Tests
Deliberately no e2e timeout changes: a dead event stream is not woken by waiting longer (only by client activity), so extended waits would neither rescue a pre-fix binary nor help a post-fix one. The always-on
rmarkdown.test.ts"empty chunk does not define variables" spec -- which runs in every PR's server-linux e2e job and exercises exactly the restart -> event-delivery -> run-chunks path -- keeps its tight 60s budget and serves as the regression canary for this fix (now noted in a comment there).Verification
ant javacpasses; e2etsc --noEmitpasses.