@@ -21,8 +21,8 @@ import { canExtensionServiceServerWork } from '../local-ssh/ipc/extensionService
2121export interface ILocalSSHService {
2222 flow ?: UserFlowTelemetryProperties ;
2323 isSupportLocalSSH : boolean ;
24- initialized : Promise < void > ;
25- prepareInitialize : ( ) => void ;
24+
25+ initialize : ( ) => Promise < void > ;
2626 extensionServerReady : ( ) => Promise < boolean > ;
2727}
2828
@@ -32,9 +32,11 @@ type FailedToInitializeCode = 'Unknown' | 'LockFailed' | string;
3232const IgnoredFailedCodes : FailedToInitializeCode [ ] = [ 'ENOSPC' ] ;
3333
3434export class LocalSSHService extends Disposable implements ILocalSSHService {
35+ private initPromise ! : Promise < void > ;
36+
3537 public isSupportLocalSSH : boolean = false ;
36- public initialized ! : Promise < void > ;
3738 public flow ?: UserFlowTelemetryProperties ;
39+
3840 constructor (
3941 private readonly context : vscode . ExtensionContext ,
4042 private readonly hostService : IHostService ,
@@ -45,8 +47,12 @@ export class LocalSSHService extends Disposable implements ILocalSSHService {
4547 super ( ) ;
4648 }
4749
48- prepareInitialize ( ) {
49- this . initialized = this . initialize ( ) ;
50+ async initialize ( ) : Promise < void > {
51+ if ( this . initPromise ) {
52+ return this . initPromise ;
53+ }
54+
55+ this . initPromise = this . doInitialize ( ) ;
5056 this . _register ( vscode . workspace . onDidChangeConfiguration ( async e => {
5157 if (
5258 e . affectsConfiguration ( 'gitpod.lsshExtensionIpcPort' ) ||
@@ -59,13 +65,15 @@ export class LocalSSHService extends Disposable implements ILocalSSHService {
5965 // event, so ignore it if more settings are affected at the same time.
6066 return ;
6167 }
62- if ( this . initialized ) {
63- await this . initialized ;
64- }
65- this . initialized = this . initialize ( ) ;
68+
69+ await this . initPromise ;
70+ this . initPromise = this . doInitialize ( ) ;
6671 }
6772 } ) ) ;
73+
74+ return this . initPromise ;
6875 }
76+
6977 async extensionServerReady ( ) : Promise < boolean > {
7078 try {
7179 await canExtensionServiceServerWork ( ) ;
@@ -91,34 +99,35 @@ export class LocalSSHService extends Disposable implements ILocalSSHService {
9199 }
92100 }
93101
94- private async initialize ( ) {
102+ private async doInitialize ( ) {
95103 let failureCode : FailedToInitializeCode | undefined ;
96- const useLocalAPP = String ( Configuration . getUseLocalApp ( ) ) ;
97- const lockFolder = vscode . Uri . joinPath ( this . context . globalStorageUri , 'initialize.lock' ) ;
98104 try {
105+ const lockFolder = vscode . Uri . joinPath ( this . context . globalStorageUri , 'initialize' ) ;
99106 await this . lock ( lockFolder . fsPath , async ( ) => {
100107 const locations = await this . copyProxyScript ( ) ;
101108 await this . configureSettings ( locations ) ;
102109 this . isSupportLocalSSH = true ;
103110 } ) ;
104111 } catch ( e ) {
105- this . logService . error ( e , 'failed to initialize' ) ;
112+ this . logService . error ( 'Failed to initialize ssh proxy config' , e ) ;
113+
106114 let sendErrorReport = true ;
107115 failureCode = 'Unknown' ;
108116 if ( e ?. code ) {
109117 failureCode = e . code ;
110- sendErrorReport = ! IgnoredFailedCodes . includes ( e . code )
118+ sendErrorReport = ! IgnoredFailedCodes . includes ( e . code ) ;
111119 }
112120 if ( e ?. message ) {
113121 e . message = `Failed to initialize: ${ e . message } ` ;
114122 }
115123 if ( sendErrorReport ) {
116- this . telemetryService . sendTelemetryException ( e , { gitpodHost : this . hostService . gitpodHost , useLocalAPP } ) ;
124+ this . telemetryService . sendTelemetryException ( e , { gitpodHost : this . hostService . gitpodHost , useLocalAPP : String ( Configuration . getUseLocalApp ( ) ) } ) ;
117125 }
118126 this . isSupportLocalSSH = false ;
119127 }
120- const flowData = this . flow ? this . flow : { gitpodHost : this . hostService . gitpodHost , userId : this . sessionService . safeGetUserId ( ) } ;
121- this . telemetryService . sendUserFlowStatus ( this . isSupportLocalSSH ? 'success' : 'failure' , { ...flowData , flow : 'local_ssh_config' , failureCode, useLocalAPP } ) ;
128+
129+ const flowData = this . flow ?? { gitpodHost : this . hostService . gitpodHost , userId : this . sessionService . safeGetUserId ( ) } ;
130+ this . telemetryService . sendUserFlowStatus ( this . isSupportLocalSSH ? 'success' : 'failure' , { ...flowData , flow : 'local_ssh_config' , failureCode, useLocalAPP : String ( Configuration . getUseLocalApp ( ) ) } ) ;
122131 }
123132
124133 private async configureSettings ( { proxyScript, launcher } : { proxyScript : string ; launcher : string } ) {
0 commit comments