Skip to content

Commit c35d558

Browse files
committed
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
1 parent 8cb4e2c commit c35d558

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

ci/dev/vscode.patch

+57-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ index 3715cbb8e6ee41c3d9b5090918d243b723ae2d00..c65de8ad37e727d66da97a8f8b170cbc
734734
-
735735
-
736736
diff --git a/src/vs/platform/remote/common/remoteAgentConnection.ts b/src/vs/platform/remote/common/remoteAgentConnection.ts
737-
index fdd5890c69f72025b94913380f0d226226e8c8fb..e084236526b38c1144d47b8b3000b367c3207fe8 100644
737+
index fdd5890c69f72025b94913380f0d226226e8c8fb..957b4812783f6b1d97d1003c63725f541042059f 100644
738738
--- a/src/vs/platform/remote/common/remoteAgentConnection.ts
739739
+++ b/src/vs/platform/remote/common/remoteAgentConnection.ts
740740
@@ -93,7 +93,7 @@ async function connectToRemoteExtensionHostAgent(options: ISimpleConnectionOptio
@@ -746,6 +746,25 @@ index fdd5890c69f72025b94913380f0d226226e8c8fb..e084236526b38c1144d47b8b3000b367
746746
(err: any, socket: ISocket | undefined) => {
747747
if (err || !socket) {
748748
options.logService.error(`${logPrefix} socketFactory.connect() failed. Error:`);
749+
@@ -338,7 +338,8 @@ export class ReconnectionWaitEvent {
750+
public readonly type = PersistentConnectionEventType.ReconnectionWait;
751+
constructor(
752+
public readonly durationSeconds: number,
753+
- private readonly cancellableTimer: CancelablePromise<void>
754+
+ private readonly cancellableTimer: CancelablePromise<void>,
755+
+ public readonly connectionAttempt: number
756+
) { }
757+
758+
public skipWait(): void {
759+
@@ -422,7 +423,7 @@ abstract class PersistentConnection extends Disposable {
760+
const waitTime = (attempt < TIMES.length ? TIMES[attempt] : TIMES[TIMES.length - 1]);
761+
try {
762+
const sleepPromise = sleep(waitTime);
763+
- this._onDidStateChange.fire(new ReconnectionWaitEvent(waitTime, sleepPromise));
764+
+ this._onDidStateChange.fire(new ReconnectionWaitEvent(waitTime, sleepPromise, attempt+1));
765+
766+
this._options.logService.info(`${logPrefix} waiting for ${waitTime} seconds before reconnecting...`);
767+
try {
749768
diff --git a/src/vs/platform/storage/browser/storageService.ts b/src/vs/platform/storage/browser/storageService.ts
750769
index ab3fd347b69f8a3d9b96e706cd87c911b8ffed6b..9d351037b577f9f1edfd18ae9b3c48a211f4467f 100644
751770
--- a/src/vs/platform/storage/browser/storageService.ts
@@ -3875,6 +3894,43 @@ index 94e7e7a4bac154c45078a1b5034e50634a7a43af..8164200dcef1efbc65b50eef9c270af3
38753894
this._filenameKey.set(value ? basename(value) : null);
38763895
this._dirnameKey.set(value ? dirname(value).fsPath : null);
38773896
this._pathKey.set(value ? value.fsPath : null);
3897+
diff --git a/src/vs/workbench/contrib/remote/browser/remote.ts b/src/vs/workbench/contrib/remote/browser/remote.ts
3898+
index c6d98b601a3b6966e8a99d2c05b3b7f02b08e6ca..c2a76fbd75d24d509f312cb8bf094eb297374f04 100644
3899+
--- a/src/vs/workbench/contrib/remote/browser/remote.ts
3900+
+++ b/src/vs/workbench/contrib/remote/browser/remote.ts
3901+
@@ -778,17 +778,30 @@ class RemoteAgentConnectionStatusListener implements IWorkbenchContribution {
3902+
}
3903+
switch (e.type) {
3904+
case PersistentConnectionEventType.ConnectionLost:
3905+
+ break;
3906+
+ case PersistentConnectionEventType.ReconnectionWait:
3907+
+ const BACKGROUND_RECONNECT_THRESHOLD = 2;
3908+
+ // If the first reconnect fails, we show the popup.
3909+
+ // This corresponds to about 5s wait.
3910+
+ if (e.connectionAttempt < BACKGROUND_RECONNECT_THRESHOLD) {
3911+
+ break;
3912+
+ }
3913+
+
3914+
if (!visibleProgress) {
3915+
visibleProgress = showProgress(ProgressLocation.Dialog, [reconnectButton, reloadButton]);
3916+
}
3917+
visibleProgress.report(nls.localize('connectionLost', "Connection Lost"));
3918+
- break;
3919+
- case PersistentConnectionEventType.ReconnectionWait:
3920+
+
3921+
reconnectWaitEvent = e;
3922+
visibleProgress = showProgress(lastLocation || ProgressLocation.Notification, [reconnectButton, reloadButton]);
3923+
visibleProgress.startTimer(Date.now() + 1000 * e.durationSeconds);
3924+
break;
3925+
case PersistentConnectionEventType.ReconnectionRunning:
3926+
+ if (!visibleProgress) {
3927+
+ // Our background reconnection threshold hasn't been hit yet.
3928+
+ break;
3929+
+ }
3930+
+
3931+
visibleProgress = showProgress(lastLocation || ProgressLocation.Notification, [reloadButton]);
3932+
visibleProgress.report(nls.localize('reconnectionRunning', "Attempting to reconnect..."));
3933+
38783934
diff --git a/src/vs/workbench/contrib/scm/browser/media/scm.css b/src/vs/workbench/contrib/scm/browser/media/scm.css
38793935
index 74f6922e98b4bb6a7fb100f5aac015afe9fc171b..3243a97c2d378013d96ffbe87e9df6dd4a66776d 100644
38803936
--- a/src/vs/workbench/contrib/scm/browser/media/scm.css

0 commit comments

Comments
 (0)