@@ -21,8 +21,8 @@ import { canExtensionServiceServerWork } from '../local-ssh/ipc/extensionService
21
21
export interface ILocalSSHService {
22
22
flow ?: UserFlowTelemetryProperties ;
23
23
isSupportLocalSSH : boolean ;
24
- initialized : Promise < void > ;
25
- prepareInitialize : ( ) => void ;
24
+
25
+ initialize : ( ) => Promise < void > ;
26
26
extensionServerReady : ( ) => Promise < boolean > ;
27
27
}
28
28
@@ -32,9 +32,11 @@ type FailedToInitializeCode = 'Unknown' | 'LockFailed' | string;
32
32
const IgnoredFailedCodes : FailedToInitializeCode [ ] = [ 'ENOSPC' ] ;
33
33
34
34
export class LocalSSHService extends Disposable implements ILocalSSHService {
35
+ private initPromise ! : Promise < void > ;
36
+
35
37
public isSupportLocalSSH : boolean = false ;
36
- public initialized ! : Promise < void > ;
37
38
public flow ?: UserFlowTelemetryProperties ;
39
+
38
40
constructor (
39
41
private readonly context : vscode . ExtensionContext ,
40
42
private readonly hostService : IHostService ,
@@ -45,8 +47,12 @@ export class LocalSSHService extends Disposable implements ILocalSSHService {
45
47
super ( ) ;
46
48
}
47
49
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 ( ) ;
50
56
this . _register ( vscode . workspace . onDidChangeConfiguration ( async e => {
51
57
if (
52
58
e . affectsConfiguration ( 'gitpod.lsshExtensionIpcPort' ) ||
@@ -59,13 +65,15 @@ export class LocalSSHService extends Disposable implements ILocalSSHService {
59
65
// event, so ignore it if more settings are affected at the same time.
60
66
return ;
61
67
}
62
- if ( this . initialized ) {
63
- await this . initialized ;
64
- }
65
- this . initialized = this . initialize ( ) ;
68
+
69
+ await this . initPromise ;
70
+ this . initPromise = this . doInitialize ( ) ;
66
71
}
67
72
} ) ) ;
73
+
74
+ return this . initPromise ;
68
75
}
76
+
69
77
async extensionServerReady ( ) : Promise < boolean > {
70
78
try {
71
79
await canExtensionServiceServerWork ( ) ;
@@ -91,34 +99,35 @@ export class LocalSSHService extends Disposable implements ILocalSSHService {
91
99
}
92
100
}
93
101
94
- private async initialize ( ) {
102
+ private async doInitialize ( ) {
95
103
let failureCode : FailedToInitializeCode | undefined ;
96
- const useLocalAPP = String ( Configuration . getUseLocalApp ( ) ) ;
97
- const lockFolder = vscode . Uri . joinPath ( this . context . globalStorageUri , 'initialize.lock' ) ;
98
104
try {
105
+ const lockFolder = vscode . Uri . joinPath ( this . context . globalStorageUri , 'initialize' ) ;
99
106
await this . lock ( lockFolder . fsPath , async ( ) => {
100
107
const locations = await this . copyProxyScript ( ) ;
101
108
await this . configureSettings ( locations ) ;
102
109
this . isSupportLocalSSH = true ;
103
110
} ) ;
104
111
} catch ( e ) {
105
- this . logService . error ( e , 'failed to initialize' ) ;
112
+ this . logService . error ( 'Failed to initialize ssh proxy config' , e ) ;
113
+
106
114
let sendErrorReport = true ;
107
115
failureCode = 'Unknown' ;
108
116
if ( e ?. code ) {
109
117
failureCode = e . code ;
110
- sendErrorReport = ! IgnoredFailedCodes . includes ( e . code )
118
+ sendErrorReport = ! IgnoredFailedCodes . includes ( e . code ) ;
111
119
}
112
120
if ( e ?. message ) {
113
121
e . message = `Failed to initialize: ${ e . message } ` ;
114
122
}
115
123
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 ( ) ) } ) ;
117
125
}
118
126
this . isSupportLocalSSH = false ;
119
127
}
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 ( ) ) } ) ;
122
131
}
123
132
124
133
private async configureSettings ( { proxyScript, launcher } : { proxyScript : string ; launcher : string } ) {
0 commit comments