Repository navigation
speed up session suspend/shutdown after interrupt - #18091
Conversation
When rserver shuts down (e.g. on Ctrl-C or service stop) it sends SIGTERM to each rsession, which in server mode triggers a forced suspend. Two parts of that path added several seconds of avoidable delay: - The client event service gave the browser a 4-second "last chance" to retrieve final events on stop. During a server shutdown the HTTP front door is already closed, so that wait always timed out in full. stop() now takes a flushPendingEvents flag (false on a forced suspend), and the run loop also skips the wait when no client connection has been serviced recently -- so an unreachable client no longer costs 4s. - Saving R options serialized a handful of RStudio-managed, function-valued options (connectionObserver, terminal.manager, reticulate.repl.*, and RStudio's own error handler) whose closures capture the large internal .rs tools environment, costing ~0.7-0.8s each. These are re-established on every session start, so .rs.saveOptions now drops them before serializing. The error option is only dropped when it is one RStudio installed (identified by the rstudioErrorHandler tag on the embedded function); user-supplied handlers are preserved. Together these cut a forced suspend on an otherwise-empty session from several seconds to well under one.
🍎 macOS Desktop E2E · ARM64✅ All tests passed!
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · macos-26 ARM64 · commit |
🐧 Linux Server E2E · Ubuntu 24✅ All tests passed!
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · ubuntu-24.04 · commit |
🐧 Linux Desktop E2E · Ubuntu 24✅ All tests passed!
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · ubuntu-24.04 · commit |
🪟 Windows Desktop E2E · Server 2025 x64✅ All tests passed!
📥 Download Playwright report⬇️ playwright-report.zip — extract and open
2 shards · Windows Server 2025 x64 · commit |
Summary
When
rservershuts down (e.g.Ctrl-Corrstudio-server stop) it sendsSIGTERMto eachrsession, which in server mode triggers a forced suspend. Investigating why that took several seconds even for an idle, empty session turned up two avoidable delays, both fixed here.1. Client event service: 4s "last chance" wait that can't succeed
ClientEventService::stop()gave the browser akLastChanceWaitSeconds(4s) window to retrieve any remaining events. During a server shutdown the HTTP front door is already closed (rserverstops serving before signaling children), so no client can connect and the wait always elapsed in full.stop()now takesflushPendingEvents(defaulttrue).rCleanuppasses!suspend::suspendedForcibly(), so a forced suspend skips the wait entirely.eventsConnectionQueue().lastConnectionTime()), so an idle/closed client on a non-forced (e.g. timeout) suspend doesn't pay the 4s either. A genuinely connected client still gets its events (delivered on the held long-poll connection, and via a fast reconnect).2.
saveOptions: serializing RStudio-managed function options.rs.saveOptionsserialized a few RStudio-managed, function-valued options whose closures capture the large internal.rstools environment, costing ~0.7-0.8s each even with an empty workspace:connectionObserver,terminal.manager,reticulate.repl.*, and RStudio's ownerrorhandler. All of these are re-established on every session start, so they are now dropped before serialization.erroris only dropped when it is a handler RStudio installed (identified by therstudioErrorHandlerattribute on the function embedded in the option's call object); user-supplied error handlers are preserved.Impact
A forced suspend on an otherwise-empty server session drops from ~4-5s to well under 1s (measured via temporary per-phase instrumentation, since removed).
Notes
Ctrl-Conrserver) and a quit on a connected session, confirming the event-flush still occurs for connected clients and that a user-setoptions(error=)survives suspend/resume.