File tree Expand file tree Collapse file tree 1 file changed +26
-2
lines changed
extensions/ql-vscode/src/query-server Expand file tree Collapse file tree 1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -240,8 +240,32 @@ export class QueryServerClient extends DisposableObject {
240
240
this . nextCallback = 0 ;
241
241
this . nextProgress = 0 ;
242
242
this . progressCallbacks = { } ;
243
- child . on ( "close" , ( ) => {
244
- this . restartQueryServerOnFailure ( ) ;
243
+
244
+ // 'exit' may or may not fire after 'error' event, so we want to guard against restarting the
245
+ // query server twice if both events fire.
246
+ let wasExitOrErrorHandled = false ;
247
+ child . on ( "error" , ( err : Error ) => {
248
+ if ( ! wasExitOrErrorHandled ) {
249
+ void this . logger . log ( `Query server terminated with error: ${ err } .` ) ;
250
+ this . restartQueryServerOnFailure ( ) ;
251
+ wasExitOrErrorHandled = true ;
252
+ }
253
+ } ) ;
254
+ child . on ( "exit" , ( code : number , signal : string ) => {
255
+ if ( ! wasExitOrErrorHandled ) {
256
+ if ( code !== null ) {
257
+ void this . logger . log (
258
+ `Query server terminated with exit code: ${ code } .` ,
259
+ ) ;
260
+ }
261
+ if ( signal !== null ) {
262
+ void this . logger . log (
263
+ `Query server terminated due to receipt of signal: ${ signal } .` ,
264
+ ) ;
265
+ }
266
+ this . restartQueryServerOnFailure ( ) ;
267
+ wasExitOrErrorHandled = true ;
268
+ }
245
269
} ) ;
246
270
}
247
271
You can’t perform that action at this time.
0 commit comments