@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
7
7
import { Command } from '../commandManager' ;
8
8
import { ISessionService } from '../services/sessionService' ;
9
9
import { WorkspaceData , rawWorkspaceToWorkspaceData } from '../publicApi' ;
10
- import { NoExtensionIPCServerError , NoLocalSSHSupportError , SSHConnectionParams , SSH_DEST_KEY , getLocalSSHDomain } from '../remote' ;
10
+ import { SSHConnectionParams , SSH_DEST_KEY , getLocalSSHDomain } from '../remote' ;
11
11
import SSHDestination from '../ssh/sshDestination' ;
12
12
import { IHostService } from '../services/hostService' ;
13
13
import { WorkspaceState } from '../workspaceState' ;
@@ -16,7 +16,7 @@ import { eventToPromise, raceCancellationError } from '../common/event';
16
16
import { ITelemetryService } from '../common/telemetry' ;
17
17
import { IRemoteService } from '../services/remoteService' ;
18
18
import { WrapError } from '../common/utils' ;
19
- import { getOpenSSHVersion } from '../ssh/sshVersion ' ;
19
+ import { getOpenSSHVersion , testSSHConnection as testLocalSSHConnection } from '../ssh/nativeSSH ' ;
20
20
import { IExperimentsService } from '../experiments' ;
21
21
22
22
function getCommandName ( command : string ) {
@@ -124,12 +124,27 @@ export class ConnectInNewWindowCommand implements Command {
124
124
wsData = wsState . workspaceData ; // Update wsData with latest info after workspace is running
125
125
}
126
126
127
+ const domain = getLocalSSHDomain ( this . hostService . gitpodHost ) ;
128
+ const sshHostname = `${ wsData ! . id } .${ domain } ` ;
129
+ const localSSHDestination = new SSHDestination ( sshHostname , wsData ! . id ) ;
130
+ 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 , 'Unknown' ) ,
137
+ {
138
+ gitpodHost : this . hostService . gitpodHost ,
139
+ workspaceId : wsData ! . id ,
140
+ }
141
+ ) ;
142
+ }
143
+
127
144
let sshDest : SSHDestination ;
128
145
let password : string | undefined ;
129
- if ( await this . experimentsService . getUseLocalSSHProxy ( ) ) {
130
- const domain = getLocalSSHDomain ( this . hostService . gitpodHost ) ;
131
- const sshHostname = `${ wsData ! . id } .${ domain } ` ;
132
- sshDest = new SSHDestination ( sshHostname , wsData ! . id ) ;
146
+ if ( await this . experimentsService . getUseLocalSSHProxy ( ) && localSSHTestSuccess ) {
147
+ sshDest = localSSHDestination ;
133
148
} else {
134
149
( { destination : sshDest , password } = await this . remoteService . getWorkspaceSSHDestination ( wsData ! ) ) ;
135
150
}
@@ -163,16 +178,10 @@ export class ConnectInNewWindowCommand implements Command {
163
178
164
179
private async initializeLocalSSH ( workspaceId : string ) {
165
180
try {
166
- const [ isSupportLocalSSH , isExtensionServerReady ] = await Promise . all ( [
181
+ await Promise . all ( [
167
182
this . remoteService . setupSSHProxy ( ) ,
168
- this . remoteService . extensionServerReady ( )
183
+ this . remoteService . startLocalSSHServiceServer ( )
169
184
] ) ;
170
- if ( ! isExtensionServerReady ) {
171
- throw new NoExtensionIPCServerError ( ) ;
172
- }
173
- if ( ! isSupportLocalSSH ) {
174
- throw new NoLocalSSHSupportError ( ) ;
175
- }
176
185
} catch ( e ) {
177
186
const openSSHVersion = await getOpenSSHVersion ( ) ;
178
187
this . telemetryService . sendTelemetryException ( new WrapError ( 'Local SSH: failed to initialize local SSH' , e ) , {
@@ -279,12 +288,27 @@ export class ConnectInCurrentWindowCommand implements Command {
279
288
wsData = wsState . workspaceData ; // Update wsData with latest info after workspace is running
280
289
}
281
290
291
+ const domain = getLocalSSHDomain ( this . hostService . gitpodHost ) ;
292
+ const sshHostname = `${ wsData ! . id } .${ domain } ` ;
293
+ const localSSHDestination = new SSHDestination ( sshHostname , wsData ! . id ) ;
294
+ 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 , 'Unknown' ) ,
301
+ {
302
+ gitpodHost : this . hostService . gitpodHost ,
303
+ workspaceId : wsData ! . id ,
304
+ }
305
+ ) ;
306
+ }
307
+
282
308
let sshDest : SSHDestination ;
283
309
let password : string | undefined ;
284
- if ( await this . experimentsService . getUseLocalSSHProxy ( ) ) {
285
- const domain = getLocalSSHDomain ( this . hostService . gitpodHost ) ;
286
- const sshHostname = `${ wsData ! . id } .${ domain } ` ;
287
- sshDest = new SSHDestination ( sshHostname , wsData ! . id ) ;
310
+ if ( await this . experimentsService . getUseLocalSSHProxy ( ) && localSSHTestSuccess ) {
311
+ sshDest = localSSHDestination ;
288
312
} else {
289
313
( { destination : sshDest , password } = await this . remoteService . getWorkspaceSSHDestination ( wsData ! ) ) ;
290
314
}
@@ -318,16 +342,10 @@ export class ConnectInCurrentWindowCommand implements Command {
318
342
319
343
private async initializeLocalSSH ( workspaceId : string ) {
320
344
try {
321
- const [ isSupportLocalSSH , isExtensionServerReady ] = await Promise . all ( [
345
+ await Promise . all ( [
322
346
this . remoteService . setupSSHProxy ( ) ,
323
- this . remoteService . extensionServerReady ( )
347
+ this . remoteService . startLocalSSHServiceServer ( )
324
348
] ) ;
325
- if ( ! isExtensionServerReady ) {
326
- throw new NoExtensionIPCServerError ( ) ;
327
- }
328
- if ( ! isSupportLocalSSH ) {
329
- throw new NoLocalSSHSupportError ( ) ;
330
- }
331
349
} catch ( e ) {
332
350
const openSSHVersion = await getOpenSSHVersion ( ) ;
333
351
this . telemetryService . sendTelemetryException ( new WrapError ( 'Local SSH: failed to initialize local SSH' , e ) , {
0 commit comments