@@ -39,8 +39,7 @@ export class LLDBDapServer implements vscode.Disposable {
39
39
const process = child_process . spawn ( dapPath , dapArgs , options ) ;
40
40
process . on ( "error" , ( error ) => {
41
41
reject ( error ) ;
42
- this . serverProcess = undefined ;
43
- this . serverInfo = undefined ;
42
+ this . cleanUp ( process ) ;
44
43
} ) ;
45
44
process . on ( "exit" , ( code , signal ) => {
46
45
let errorMessage = "Server process exited early" ;
@@ -50,8 +49,7 @@ export class LLDBDapServer implements vscode.Disposable {
50
49
errorMessage += ` due to signal ${ signal } ` ;
51
50
}
52
51
reject ( new Error ( errorMessage ) ) ;
53
- this . serverProcess = undefined ;
54
- this . serverInfo = undefined ;
52
+ this . cleanUp ( process ) ;
55
53
} ) ;
56
54
process . stdout . setEncoding ( "utf8" ) . on ( "data" , ( data ) => {
57
55
const connection = / c o n n e c t i o n : \/ \/ \[ ( [ ^ \] ] + ) \] : ( \d + ) / . exec (
@@ -126,7 +124,16 @@ Restarting the server will interrupt any existing debug sessions and start a new
126
124
return ;
127
125
}
128
126
this . serverProcess . kill ( ) ;
129
- this . serverProcess = undefined ;
130
- this . serverInfo = undefined ;
127
+ this . cleanUp ( this . serverProcess ) ;
128
+ }
129
+
130
+ cleanUp ( process : child_process . ChildProcessWithoutNullStreams ) {
131
+ // If the following don't equal, then the fields have already been updated
132
+ // (either a new process has started, or the fields were already cleaned
133
+ // up), and so the cleanup should be skipped.
134
+ if ( this . serverProcess === process ) {
135
+ this . serverProcess = undefined ;
136
+ this . serverInfo = undefined ;
137
+ }
131
138
}
132
139
}
0 commit comments