Repository navigation
Description
Description
On RStudio Server, after an R session restart (e.g. "Restart R and Run All Chunks", or resume from suspend), the client can stop receiving events entirely until the user's next action. Symptoms:
- "Restart R and Run All Chunks" restarts R, but the chunks do not run and the console sits at "Restarting R session..." until the user does something.
- After a suspended session auto-resumes, console output is delayed until the next user action (previously observed while diagnosing the
session_suspende2e flake around PR clear pending session launches when the launched process dies #18209).
Mechanism
- The session goes down (suspend for restart); the in-flight
get_eventslong-poll fails. rserver maps a dead session socket to a jsonrpcUnavailableerror (or a bare 503, surfaced client-side as a transmission error) -- and, importantly, events requests never initiate session launches (handleEventsErrorinServerSessionProxy.cpp), so polling alone cannot bring the session back. RemoteServerEventListener.onErrorstops the listener. ForUNAVAILABLEit firesServerUnavailableEventand remains stopped with no retry; for other errors it retries at most 5 times at 500ms and then remains stopped. (NotelistenErrorCount_is never reset on success, so this is a lifetime budget: a long-lived tab that has absorbed a few transient errors over hours goes straight to give-up.)- The existing revival hooks then never fire while the user (or a test) is passively waiting:
- Every RPC send calls
ensureListeningForEvents()(RemoteServer.java:3839), but itsensureListening(10)burst is bounded (10 attempts at 250ms = 2.5s) and typically races -- and loses to -- the session relaunch, which itself only starts when an RPC arrives at rserver. In the run below, the burst's last attempt failed 1.4s before the new session finished connecting. - RPC responses only call
ensureEvents()when they report pending events ("ep": "true"). - An idle client waiting for console output sends no RPCs at all, so neither hook runs again.
- Every RPC send calls
- The client therefore stays deaf to all client events -- including
DeferredInitCompletedEvent, which is what triggers the queued "run all chunks" command -- until the user's next action sends an RPC.
Evidence
From e2e run 30025658637 (server-linux shard 1, rmarkdown.test.ts > empty chunk does not define variables, failed twice identically):
- 17:18:03
suspend_for_restartOK; session socket gone. - 17:18:08.29
set_client_statesend triggers theensureListening(10)burst: 10get_eventsat 250ms, 17:18:08.30-17:18:10.55, all failing (ENOENT at rserver); that same RPC prompts rserver to relaunch the session, which connects at 17:18:11.94 -- 1.4s after the last attempt. - 17:18:10.55 -> 17:19:08: zero
get_eventsfrom the client; the test is passively waiting on the console, so no RPCs are sent. - 17:19:08 test teardown sends
close_document; that send'sensureListeningForEvents()revives the stream and ~390KB of buffered events (restart completion, chunk output) arrive at once -- past the test's 60s wait.
The comment in RemoteServerEventListener's constructor already anticipates the need for "another way to restart the listener (perhaps a global timer that checks for isListening every few seconds)".
Activity
drop e2e timeout hardening; keep 60s waits as revival canary
harden event listener error recovery
revive client event stream after session restart (#18341)