Skip to content

Commit

Permalink
Fix reconnection errors in some multi-window workflows (#5817)
Browse files Browse the repository at this point in the history
Addresses #5750.

The underlying issue is somewhat complicated. Basically:

- The list of running sessions is stored in ephemeral storage, scoped to
the workspace.
- Ephemeral storage is shared among all active windows.
- We rely on the fact that ephemeral storage goes away when the app
quits in order to prevent reconnection to old sessions.
- It is possible however in multi-window scenarios to close and reopen a
window in a workspace *without ever quitting Positron itself*. In this
scenario, we can try to reconnect to non-existent sessions.

The fix is to manually clear out the sessions from ephemeral storage on
close/quit.

This is not related to the 1.95 merge.

### QA Notes

This does not reproduce reliably with the steps in #5750. Here are steps
that will cause it to reproduce every time in builds prior to this
change.

1. Open a workspace (Workspace 1).
2. Using the Open in New Window gesture on the Project drop down in the
upper right, open a different workspace (Workspace 2) in a new window.
3. Start Python and/or R in Workspace 2 and run a few commands.
4. Close Workspace 2, but leave the Workspace 1 window open.
5. In Workspace 1, once again use Open in New Window to open Workspace
2.

In Step 5, you will see the window attempt to connect to the sessions
that you started in Step 3, but get HTTP 404 since those sessions are
not running any more.

Also note that the purpose of this machinery is to reconnect to sessions
on reload/re-navigate, so double check that that still works.
  • Loading branch information
jmcphers authored Dec 18, 2024
1 parent 6c454a0 commit 69a2e14
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/vs/workbench/services/runtimeStartup/common/runtimeStartup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ export class RuntimeStartupService extends Disposable implements IRuntimeStartup
// before reloading the browser.
e.veto(this.saveWorkspaceSessions(),
'positron.runtimeStartup.saveWorkspaceSessions');
} else if (e.reason === ShutdownReason.CLOSE || e.reason === ShutdownReason.QUIT) {
// Clear the workspace sessions. In most cases this is not
// necessary since the sessions are stored in ephemeral
// storage, but it is possible that this workspace will be
// re-opened without an interleaving quit (e.g. if multiple
// Positron windows are open).
e.veto(this.clearWorkspaceSessions(), 'positron.runtimeStartup.clearWorkspaceSessions');
}
}));
}
Expand Down Expand Up @@ -770,6 +777,17 @@ export class RuntimeStartupService extends Disposable implements IRuntimeStartup
}));
}

/**
* Clear the set of workspace sessions in the workspace storage.
*/
private async clearWorkspaceSessions(): Promise<boolean> {
// Clear the sessions.
await this._ephemeralStateService.removeItem(this.getPersistentWorkspaceSessionsKey());

// Always return false (don't veto shutdown)
return false;
}

/**
* Update the set of workspace sessions in the workspace storage.
*
Expand Down

0 comments on commit 69a2e14

Please sign in to comment.