Skip to content

Suppress 'R Session Disconnected' dialog on Desktop and during restart - #17140

Merged
kevinushey merged 2 commits into
mainfrom
bugfix/suppress-disconnect-during-restart
Mar 2, 2026
Merged

kevinushey merged 2 commits into
mainfrom
bugfix/suppress-disconnect-during-restart

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Summary

The onClientDisconnected handler in Application.java was showing the "R Session Disconnected" popup unconditionally. This is wrong in two cases:

  1. On Desktop, where the dialog should never appear (Desktop has its own session recovery mechanism triggered by process exit).
  2. During a deliberate restart, where in-flight RPC requests may return INVALID_CLIENT_ID as the session resets, spuriously triggering the disconnect event.

Fix

Add guards for both cases in onClientDisconnected():

  • Desktop.isDesktop() check, mirroring the existing pattern in onQuit()
  • pApplicationQuit_.get().isSuspendingAndRestarting() check, using the existing accessor on ApplicationQuit

Testing

  • On Desktop, verify the "R Session Disconnected" dialog no longer appears during restart
  • On Server, verify the dialog no longer appears during a deliberate restart
  • On Server, verify the dialog still appears for genuine disconnections (e.g. network loss)

The onClientDisconnected handler was showing the disconnection
popup unconditionally. This is wrong in two cases:

1. On Desktop, where the dialog should never appear (Desktop has
   its own session recovery mechanism triggered by process exit).

2. During a deliberate restart, where in-flight RPC requests may
   return INVALID_CLIENT_ID as the session resets, spuriously
   triggering the disconnect event.

Add guards for both cases. The Desktop check mirrors the existing
pattern in onQuit(). The restart check uses the existing
isSuspendingAndRestarting() accessor on ApplicationQuit.
@posit-snyk-bot

posit-snyk-bot commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@gtritchie

Copy link
Copy Markdown
Member

Review

The logic, style, and use of existing patterns (Desktop.isDesktop(), pApplicationQuit_ injection) all look correct. The comment explains the "why" clearly, and the guard structure mirrors onQuit().

Three concerns worth discussing:

1. cleanupWorkbench() poisons the RPC layer during restart (HIGH)

cleanupWorkbench() still runs unconditionally, which calls server_.disconnect() — setting disconnected_ = true and stopping the event listener. Once that flag is set, sendRequest() short-circuits all RPCs (line 3818 of RemoteServer.java). The ping loop in waitForSessionRestart silently dies because its RPCs are dropped. The user sees no dialog (suppressed by this PR) and no recovery path — the workbench just hangs.

Suggested fix — early-return entirely when restarting:

public void onClientDisconnected(ClientDisconnectedEvent event)
{
   if (pApplicationQuit_.get().isSuspendingAndRestarting())
      return;

   cleanupWorkbench();

   if (!Desktop.isDesktop())
   {
      view_.showApplicationDisconnected();
   }
}

2. Race between suspendingAndRestarting_ clearing and late RPCs (MEDIUM)

suspendingAndRestarting_ is cleared in the onRestartComplete callback, but late-arriving INVALID_CLIENT_ID HTTP responses can be dispatched after that point. A late arrival would bypass the guard and trigger the full cleanupWorkbench() + dialog on a restart that actually succeeded. This is addressed by #17141 at the RemoteServer layer, which is a good argument for taking both PRs together.

3. Desktop suppression is unconditional (MEDIUM)

The !Desktop.isDesktop() guard suppresses the dialog for all Desktop disconnects, not just restart-related ones. A genuine disconnect that doesn't involve process exit (stale client ID, network partition on sleep/wake) would now silently kill the workbench with no user-visible indication. This is arguably acceptable if Desktop's process-exit handler covers all realistic scenarios, but worth noting. Again, #17141 helps here — if INVALID_CLIENT_ID during restart never fires ClientDisconnectedEvent in the first place, the Desktop guard only needs to handle non-restart cases where process exit is the expected recovery path.

Verdict

The core fix is sound. Issue 1 (cleanupWorkbench running during restart) should be addressed before merge. Taking this together with #17141 would provide defense in depth and neutralize the race window (issue 2) and Desktop breadth concern (issue 3).

@gtritchie gtritchie added this to the Globemaster Allium milestone Mar 1, 2026
Move the isSuspendingAndRestarting() check before cleanupWorkbench()
and return entirely. cleanupWorkbench() calls server_.disconnect(),
which sets disconnected_ = true and kills the event listener. This
would poison the RPC layer and silently break the ping loop in
waitForSessionRestart, leaving the workbench hung with no recovery.

See: #17140 (comment)

@gtritchie gtritchie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@kevinushey
kevinushey merged commit 9c8d395 into main Mar 2, 2026
8 checks passed
@kevinushey
kevinushey deleted the bugfix/suppress-disconnect-during-restart branch March 2, 2026 00:33
@kevinushey

Copy link
Copy Markdown
Collaborator Author

Pushed a fix for issue 1: the isSuspendingAndRestarting() check now early-returns before cleanupWorkbench(), preventing disconnect() from poisoning the RPC layer during restart.

Re: issues 2 and 3 — both are mitigated by #17141 at the RemoteServer layer (suppressing INVALID_CLIENT_ID → ClientDisconnectedEvent at the source during restart). Recommend merging this alongside #17141 for defense in depth.

@jcheng5

jcheng5 commented Mar 4, 2026

Copy link
Copy Markdown
Member

I don't see any "R Session Disconnected" dialog on R session restart. Tested on macOS Desktop and Ubuntu 24.04 Server.

On my first attempt restarting on Server, I got into the state where the session has restarted but PA stays grey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants