vscode: Reconnect in the background up to 5 seconds

Based on the previous commits by @mgmachado but simplified.

I also changed the threshold to error after a single attempt as the
connection has likely been borked and the user should be in the know if
they couldn't reconnect after 5 seconds.

Closes #1791
This commit is contained in:
Anmol Sethi 2020-11-30 13:23:17 -05:00
parent 8cb4e2c226
commit c35d558352
No known key found for this signature in database
GPG Key ID: 8CEF1878FF10ADEB

View File

@ -734,7 +734,7 @@ index 3715cbb8e6ee41c3d9b5090918d243b723ae2d00..c65de8ad37e727d66da97a8f8b170cbc
- -
- -
diff --git a/src/vs/platform/remote/common/remoteAgentConnection.ts b/src/vs/platform/remote/common/remoteAgentConnection.ts diff --git a/src/vs/platform/remote/common/remoteAgentConnection.ts b/src/vs/platform/remote/common/remoteAgentConnection.ts
index fdd5890c69f72025b94913380f0d226226e8c8fb..e084236526b38c1144d47b8b3000b367c3207fe8 100644 index fdd5890c69f72025b94913380f0d226226e8c8fb..957b4812783f6b1d97d1003c63725f541042059f 100644
--- a/src/vs/platform/remote/common/remoteAgentConnection.ts --- a/src/vs/platform/remote/common/remoteAgentConnection.ts
+++ b/src/vs/platform/remote/common/remoteAgentConnection.ts +++ b/src/vs/platform/remote/common/remoteAgentConnection.ts
@@ -93,7 +93,7 @@ async function connectToRemoteExtensionHostAgent(options: ISimpleConnectionOptio @@ -93,7 +93,7 @@ async function connectToRemoteExtensionHostAgent(options: ISimpleConnectionOptio
@ -746,6 +746,25 @@ index fdd5890c69f72025b94913380f0d226226e8c8fb..e084236526b38c1144d47b8b3000b367
(err: any, socket: ISocket | undefined) => { (err: any, socket: ISocket | undefined) => {
if (err || !socket) { if (err || !socket) {
options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`); options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`);
@@ -338,7 +338,8 @@ export class ReconnectionWaitEvent {
public readonly type = PersistentConnectionEventType.ReconnectionWait;
constructor(
public readonly durationSeconds: number,
- private readonly cancellableTimer: CancelablePromise<void>
+ private readonly cancellableTimer: CancelablePromise<void>,
+ public readonly connectionAttempt: number
) { }
public skipWait(): void {
@@ -422,7 +423,7 @@ abstract class PersistentConnection extends Disposable {
const waitTime = (attempt < TIMES.length ? TIMES[attempt] : TIMES[TIMES.length - 1]);
try {
const sleepPromise = sleep(waitTime);
- this._onDidStateChange.fire(new ReconnectionWaitEvent(waitTime, sleepPromise));
+ this._onDidStateChange.fire(new ReconnectionWaitEvent(waitTime, sleepPromise, attempt+1));
this._options.logService.info(`${logPrefix} waiting for ${waitTime} seconds before reconnecting...`);
try {
diff --git a/src/vs/platform/storage/browser/storageService.ts b/src/vs/platform/storage/browser/storageService.ts diff --git a/src/vs/platform/storage/browser/storageService.ts b/src/vs/platform/storage/browser/storageService.ts
index ab3fd347b69f8a3d9b96e706cd87c911b8ffed6b..9d351037b577f9f1edfd18ae9b3c48a211f4467f 100644 index ab3fd347b69f8a3d9b96e706cd87c911b8ffed6b..9d351037b577f9f1edfd18ae9b3c48a211f4467f 100644
--- a/src/vs/platform/storage/browser/storageService.ts --- a/src/vs/platform/storage/browser/storageService.ts
@ -3875,6 +3894,43 @@ index 94e7e7a4bac154c45078a1b5034e50634a7a43af..8164200dcef1efbc65b50eef9c270af3
this._filenameKey.set(value ? basename(value) : null); this._filenameKey.set(value ? basename(value) : null);
this._dirnameKey.set(value ? dirname(value).fsPath : null); this._dirnameKey.set(value ? dirname(value).fsPath : null);
this._pathKey.set(value ? value.fsPath : null); this._pathKey.set(value ? value.fsPath : null);
diff --git a/src/vs/workbench/contrib/remote/browser/remote.ts b/src/vs/workbench/contrib/remote/browser/remote.ts
index c6d98b601a3b6966e8a99d2c05b3b7f02b08e6ca..c2a76fbd75d24d509f312cb8bf094eb297374f04 100644
--- a/src/vs/workbench/contrib/remote/browser/remote.ts
+++ b/src/vs/workbench/contrib/remote/browser/remote.ts
@@ -778,17 +778,30 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution {
}
switch (e.type) {
case PersistentConnectionEventType.ConnectionLost:
+ break;
+ case PersistentConnectionEventType.ReconnectionWait:
+ const BACKGROUND_RECONNECT_THRESHOLD = 2;
+ // If the first reconnect fails, we show the popup.
+ // This corresponds to about 5s wait.
+ if (e.connectionAttempt < BACKGROUND_RECONNECT_THRESHOLD) {
+ break;
+ }
+
if (!visibleProgress) {
visibleProgress = showProgress(ProgressLocation.Dialog, [reconnectButton, reloadButton]);
}
visibleProgress.report(nls.localize('connectionLost', "Connection Lost"));
- break;
- case PersistentConnectionEventType.ReconnectionWait:
+
reconnectWaitEvent = e;
visibleProgress = showProgress(lastLocation || ProgressLocation.Notification, [reconnectButton, reloadButton]);
visibleProgress.startTimer(Date.now() + 1000 * e.durationSeconds);
break;
case PersistentConnectionEventType.ReconnectionRunning:
+ if (!visibleProgress) {
+ // Our background reconnection threshold hasn't been hit yet.
+ break;
+ }
+
visibleProgress = showProgress(lastLocation || ProgressLocation.Notification, [reloadButton]);
visibleProgress.report(nls.localize('reconnectionRunning', "Attempting to reconnect..."));
diff --git a/src/vs/workbench/contrib/scm/browser/media/scm.css b/src/vs/workbench/contrib/scm/browser/media/scm.css diff --git a/src/vs/workbench/contrib/scm/browser/media/scm.css b/src/vs/workbench/contrib/scm/browser/media/scm.css
index 74f6922e98b4bb6a7fb100f5aac015afe9fc171b..3243a97c2d378013d96ffbe87e9df6dd4a66776d 100644 index 74f6922e98b4bb6a7fb100f5aac015afe9fc171b..3243a97c2d378013d96ffbe87e9df6dd4a66776d 100644
--- a/src/vs/workbench/contrib/scm/browser/media/scm.css --- a/src/vs/workbench/contrib/scm/browser/media/scm.css