Skip to content

server: client event stream not resumed after session restart; run-all-chunks and console output stall until next user action #18340

Closed

Description

@kevinushey

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_suspend e2e flake around PR clear pending session launches when the launched process dies #18209).

Mechanism

  1. The session goes down (suspend for restart); the in-flight get_events long-poll fails. rserver maps a dead session socket to a jsonrpc Unavailable error (or a bare 503, surfaced client-side as a transmission error) -- and, importantly, events requests never initiate session launches (handleEventsError in ServerSessionProxy.cpp), so polling alone cannot bring the session back.
  2. RemoteServerEventListener.onError stops the listener. For UNAVAILABLE it fires ServerUnavailableEvent and remains stopped with no retry; for other errors it retries at most 5 times at 500ms and then remains stopped. (Note listenErrorCount_ 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.)
  3. 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 its ensureListening(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.
  4. 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_restart OK; session socket gone.
  • 17:18:08.29 set_client_state send triggers the ensureListening(10) burst: 10 get_events at 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_events from 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's ensureListeningForEvents() 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)".

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions