@@ -7,7 +7,7 @@ import * as vscode from 'vscode';
77import { Command } from '../commandManager' ;
88import { ISessionService } from '../services/sessionService' ;
99import { WorkspaceData , rawWorkspaceToWorkspaceData } from '../publicApi' ;
10- import { NoExtensionIPCServerError , NoLocalSSHSupportError , SSHConnectionParams , SSH_DEST_KEY , getLocalSSHDomain } from '../remote' ;
10+ import { SSHConnectionParams , SSH_DEST_KEY , getLocalSSHDomain } from '../remote' ;
1111import SSHDestination from '../ssh/sshDestination' ;
1212import { IHostService } from '../services/hostService' ;
1313import { WorkspaceState } from '../workspaceState' ;
@@ -16,7 +16,7 @@ import { eventToPromise, raceCancellationError } from '../common/event';
1616import { ITelemetryService } from '../common/telemetry' ;
1717import { IRemoteService } from '../services/remoteService' ;
1818import { WrapError } from '../common/utils' ;
19- import { getOpenSSHVersion } from '../ssh/sshVersion ' ;
19+ import { getOpenSSHVersion , testSSHConnection as testLocalSSHConnection } from '../ssh/nativeSSH ' ;
2020import { IExperimentsService } from '../experiments' ;
2121
2222function getCommandName ( command : string ) {
@@ -124,12 +124,27 @@ export class ConnectInNewWindowCommand implements Command {
124124 wsData = wsState . workspaceData ; // Update wsData with latest info after workspace is running
125125 }
126126
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+
127144 let sshDest : SSHDestination ;
128145 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 ;
133148 } else {
134149 ( { destination : sshDest , password } = await this . remoteService . getWorkspaceSSHDestination ( wsData ! ) ) ;
135150 }
@@ -163,16 +178,10 @@ export class ConnectInNewWindowCommand implements Command {
163178
164179 private async initializeLocalSSH ( workspaceId : string ) {
165180 try {
166- const [ isSupportLocalSSH , isExtensionServerReady ] = await Promise . all ( [
181+ await Promise . all ( [
167182 this . remoteService . setupSSHProxy ( ) ,
168- this . remoteService . extensionServerReady ( )
183+ this . remoteService . startLocalSSHServiceServer ( )
169184 ] ) ;
170- if ( ! isExtensionServerReady ) {
171- throw new NoExtensionIPCServerError ( ) ;
172- }
173- if ( ! isSupportLocalSSH ) {
174- throw new NoLocalSSHSupportError ( ) ;
175- }
176185 } catch ( e ) {
177186 const openSSHVersion = await getOpenSSHVersion ( ) ;
178187 this . telemetryService . sendTelemetryException ( new WrapError ( 'Local SSH: failed to initialize local SSH' , e ) , {
@@ -279,12 +288,27 @@ export class ConnectInCurrentWindowCommand implements Command {
279288 wsData = wsState . workspaceData ; // Update wsData with latest info after workspace is running
280289 }
281290
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+
282308 let sshDest : SSHDestination ;
283309 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 ;
288312 } else {
289313 ( { destination : sshDest , password } = await this . remoteService . getWorkspaceSSHDestination ( wsData ! ) ) ;
290314 }
@@ -318,16 +342,10 @@ export class ConnectInCurrentWindowCommand implements Command {
318342
319343 private async initializeLocalSSH ( workspaceId : string ) {
320344 try {
321- const [ isSupportLocalSSH , isExtensionServerReady ] = await Promise . all ( [
345+ await Promise . all ( [
322346 this . remoteService . setupSSHProxy ( ) ,
323- this . remoteService . extensionServerReady ( )
347+ this . remoteService . startLocalSSHServiceServer ( )
324348 ] ) ;
325- if ( ! isExtensionServerReady ) {
326- throw new NoExtensionIPCServerError ( ) ;
327- }
328- if ( ! isSupportLocalSSH ) {
329- throw new NoLocalSSHSupportError ( ) ;
330- }
331349 } catch ( e ) {
332350 const openSSHVersion = await getOpenSSHVersion ( ) ;
333351 this . telemetryService . sendTelemetryException ( new WrapError ( 'Local SSH: failed to initialize local SSH' , e ) , {
0 commit comments