Skip to content

Commit 8ce00cd

Browse files
authored
Proper start local ssh service server (#92)
* Proper start local ssh service server * 💄 * Make recent projects works
1 parent d400d53 commit 8ce00cd

File tree

4 files changed

+42
-31
lines changed

4 files changed

+42
-31
lines changed

src/commands/workspaces.ts

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class ConnectInNewWindowCommand implements Command {
108108
cancellable: true
109109
},
110110
async (_, cancelToken) => {
111-
await this.initializeLocalSSH(wsData!.id);
111+
const localSSHInitSuccess = await this.initializeLocalSSH(wsData!.id);
112112

113113
if (wsState.isWorkspaceStopped) {
114114
// Start workspace automatically
@@ -128,18 +128,20 @@ export class ConnectInNewWindowCommand implements Command {
128128
const sshHostname = `${wsData!.id}.${domain}`;
129129
const localSSHDestination = new SSHDestination(sshHostname, wsData!.id);
130130
let localSSHTestSuccess: boolean = false;
131-
try {
132-
await testLocalSSHConnection(localSSHDestination.user!, localSSHDestination.hostname);
133-
localSSHTestSuccess = true;
134-
} catch (e) {
135-
this.telemetryService.sendTelemetryException(
136-
new WrapError('Local SSH: failed to connect to workspace', e),
137-
{
138-
gitpodHost: this.hostService.gitpodHost,
139-
openSSHVersion: await getOpenSSHVersion(),
140-
workspaceId: wsData!.id,
141-
}
142-
);
131+
if (localSSHInitSuccess) {
132+
try {
133+
await testLocalSSHConnection(localSSHDestination.user!, localSSHDestination.hostname);
134+
localSSHTestSuccess = true;
135+
} catch (e) {
136+
this.telemetryService.sendTelemetryException(
137+
new WrapError('Local SSH: failed to connect to workspace', e),
138+
{
139+
gitpodHost: this.hostService.gitpodHost,
140+
openSSHVersion: await getOpenSSHVersion(),
141+
workspaceId: wsData!.id,
142+
}
143+
);
144+
}
143145
}
144146

145147
let sshDest: SSHDestination;
@@ -183,6 +185,7 @@ export class ConnectInNewWindowCommand implements Command {
183185
this.remoteService.setupSSHProxy(),
184186
this.remoteService.startLocalSSHServiceServer()
185187
]);
188+
return true;
186189
} catch (e) {
187190
this.telemetryService.sendTelemetryException(new WrapError('Local SSH: failed to initialize local SSH', e), {
188191
gitpodHost: this.hostService.gitpodHost,
@@ -191,6 +194,7 @@ export class ConnectInNewWindowCommand implements Command {
191194

192195
});
193196
this.logService.error(`Local SSH: failed to initialize local SSH`, e);
197+
return false;
194198
}
195199
}
196200
}
@@ -272,7 +276,7 @@ export class ConnectInCurrentWindowCommand implements Command {
272276
cancellable: true
273277
},
274278
async (_, cancelToken) => {
275-
await this.initializeLocalSSH(wsData!.id);
279+
const localSSHInitSuccess = await this.initializeLocalSSH(wsData!.id);
276280

277281
if (wsState.isWorkspaceStopped) {
278282
// Start workspace automatically
@@ -292,18 +296,21 @@ export class ConnectInCurrentWindowCommand implements Command {
292296
const sshHostname = `${wsData!.id}.${domain}`;
293297
const localSSHDestination = new SSHDestination(sshHostname, wsData!.id);
294298
let localSSHTestSuccess: boolean = false;
295-
try {
296-
await testLocalSSHConnection(localSSHDestination.user!, localSSHDestination.hostname);
297-
localSSHTestSuccess = true;
298-
} catch (e) {
299-
this.telemetryService.sendTelemetryException(
300-
new WrapError('Local SSH: failed to connect to workspace', e),
301-
{
302-
gitpodHost: this.hostService.gitpodHost,
303-
openSSHVersion: await getOpenSSHVersion(),
304-
workspaceId: wsData!.id,
305-
}
306-
);
299+
if (localSSHInitSuccess) {
300+
try {
301+
// TODO: test without check results of initializeLocalSSH will make test failed more often
302+
await testLocalSSHConnection(localSSHDestination.user!, localSSHDestination.hostname);
303+
localSSHTestSuccess = true;
304+
} catch (e) {
305+
this.telemetryService.sendTelemetryException(
306+
new WrapError('Local SSH: failed to connect to workspace', e),
307+
{
308+
gitpodHost: this.hostService.gitpodHost,
309+
openSSHVersion: await getOpenSSHVersion(),
310+
workspaceId: wsData!.id,
311+
}
312+
);
313+
}
307314
}
308315

309316
let sshDest: SSHDestination;
@@ -347,6 +354,7 @@ export class ConnectInCurrentWindowCommand implements Command {
347354
this.remoteService.setupSSHProxy(),
348355
this.remoteService.startLocalSSHServiceServer()
349356
]);
357+
return true;
350358
} catch (e) {
351359
this.telemetryService.sendTelemetryException(new WrapError('Local SSH: failed to initialize local SSH', e), {
352360
gitpodHost: this.hostService.gitpodHost,
@@ -355,6 +363,7 @@ export class ConnectInCurrentWindowCommand implements Command {
355363

356364
});
357365
this.logService.error(`Local SSH: failed to initialize local SSH`, e);
366+
return false;
358367
}
359368
}
360369
}

src/remoteConnector.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,10 @@ export class RemoteConnector extends Disposable {
676676
if (!this.sessionService.isSignedIn() || new URL(this.hostService.gitpodHost).host !== new URL(params.gitpodHost).host /* remote window case so host didn't update*/) {
677677
return;
678678
}
679+
const useLocalSSH = await this.experiments.getUseLocalSSHProxy();
679680

680681
sshFlow.userId = this.sessionService.getUserId();
682+
sshFlow.useLocalSSH = useLocalSSH;
681683

682684
this.logService.info('Opening Gitpod workspace', uri.toString());
683685

@@ -725,7 +727,7 @@ export class RemoteConnector extends Disposable {
725727

726728
let sshDestination: SSHDestination | undefined;
727729

728-
if (await this.experiments.getUseLocalSSHProxy() && localSSHTestSuccess) {
730+
if (useLocalSSH && localSSHTestSuccess) {
729731
this.logService.info('Going to use lssh');
730732
sshDestination = localSSHDestination;
731733
params.connType = 'local-ssh';

src/remoteSession.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,7 @@ export class RemoteSession extends Disposable {
6565
}
6666

6767
try {
68-
const useLocalSSH = await this.experiments.getUseLocalSSHProxy();
69-
if (useLocalSSH) {
70-
this.remoteService.startLocalSSHServiceServer().catch(() => {/* ignore */ });
71-
}
68+
this.remoteService.startLocalSSHServiceServer().catch(() => {/* ignore */ });
7269

7370
this.usePublicApi = await this.experiments.getUsePublicAPI(this.connectionInfo.gitpodHost);
7471
this.logService.info(`Going to use ${this.usePublicApi ? 'public' : 'server'} API`);

src/services/remoteService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,15 @@ export class RemoteService extends Disposable implements IRemoteService {
9393
}
9494

9595
async startLocalSSHServiceServer() {
96+
this.logService.trace('Starting local ssh service server');
9697
if (!this.extensionServiceServer) {
9798
this.extensionServiceServer = this._register(new ExtensionServiceServer(this.logService, this.sessionService, this.hostService, this.telemetryService));
9899
}
99100

100101
try {
101102
await this.extensionServiceServer.canExtensionServiceServerWork();
102103
this.metricsReporter.reportPingExtensionStatus(this.hostService.gitpodHost, 'success');
104+
this.logService.trace('Local ssh service server started');
103105
} catch (e) {
104106
const failureCode = 'ExtensionServerUnavailable';
105107
const flow = {
@@ -110,6 +112,7 @@ export class RemoteService extends Disposable implements IRemoteService {
110112
failureCode,
111113
};
112114
const err = new WrapError('cannot ping extension ipc service server', e, failureCode);
115+
this.logService.error('Failed start local ssh service server', err);
113116
this.telemetryService.sendTelemetryException(err, {
114117
gitpodHost: flow.gitpodHost,
115118
userId: flow.userId,

0 commit comments

Comments
 (0)