RStudio Connect load balancer and Shiny session lifecycle: can in-flight sessions survive a version redeploy?
0 reputation · 17 Dec 2023, 20:25 UTC
0 reputation · 17 Dec 2023, 20:25 UTC
We run a small Shiny application behind RStudio Connect's built-in load balancing and want to deploy new versions without kicking out users who are mid-session. My understanding is that each deployment creates a new content bundle with its own package library, and that Connect tears down the existing R processes rather than migrating them.
The uncertainty is at the boundary between the Connect scheduler and the Shiny runtime. Shiny's reactive state lives in R process memory, and I have not found a supported way to serialize reactive values, input bindings, or renderers across process boundaries. I also believe session$onSessionEnded only fires on clean client disconnects, not on server-initiated termination during a deploy, which would mean cleanup code never runs. Assume a recent Connect release (2023.09 or later).
Specific questions:
connectapi package (or the Server API) enumerate or signal individual active user sessions, or is teardown always unconditional?redux) is the only path, is there a documented reconnect flow so returning clients rebuild UI state against the new version?33275 reputation · 18 Dec 2023, 02:49 UTC
No – in‑flight Shiny sessions are terminated when RStudio Connect redeploys a new version of the app.
connectapi package) lists apps, users, and deployment status but does not provide endpoints to enumerate or signal individual Shiny sessions.session$onSessionEnded fires only on normal client disconnects; it is not invoked when the server process is killed during a redeploy, so cleanup code does not run.Connect’s load balancer routes traffic to the newest bundle as soon as the new R processes are ready. Because Shiny’s reactive state lives only in the R process memory and there is no built‑in mechanism to serialize or transfer that state, the balancer cannot migrate sessions; it simply switches the routing table and the old processes are killed.
session$onSessionEnded handler that writes a cleanup marker to the external store; note that this handler will not run during a server‑initiated kill, so rely on the startup check rather than the handler for state recovery.Do you already persist any reactive state outside the R process? If you do, the recommendation is to verify that the reconnect logic works; if you do not, externalizing state is the only path forward.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.