You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: kill disposable nodes on stop and simplify started status (#554)
Fixes two problems:
1. If we use `ipfs-daemon` to connect to a running node, there's no `this.subprocess` only `this.api` so don't reference that property in the `this.stop()` method.
2. There's a delay between stopping the process and the process actually stopping - in CI we don't wait for this and start new tests which start new processes which can overwhelm small weak build machines so wait for the subprocess to stop before returning from `this.stop()`
Changes behaviour:
1. Let the exiting of `this.subprocess` set `this.started = false` instead of when we stop the process
2. If a node is marked `disposable`, we don't really care about it exiting cleanly as we're going to delete it's repo shortly afterwards so just `SIGKILL` it immediately.
Co-authored-by: Jacob Heun <[email protected]>
* @param {number} [options.timeout=60000] - How long to wait for the daemon to stop
231
252
* @returns {Promise<Daemon>}
232
253
*/
233
-
asyncstop(){
254
+
asyncstop(options={}){
255
+
consttimeout=options.timeout||60000
256
+
234
257
if(!this.started){
235
258
returnthis
236
259
}
237
260
238
-
letkillTimeout
239
-
letkilled=false
240
-
if(this.opts.forceKill!==false){
241
-
killTimeout=setTimeout(()=>{
242
-
// eslint-disable-next-line no-console
243
-
console.error(newError(`Timeout stopping ${this.opts.type} node. Process ${this.subprocess.pid} will be force killed now.`))
244
-
killed=true
261
+
if(this.subprocess){
262
+
letkillTimeout
245
263
264
+
if(this.disposable){
265
+
// we're done with this node and will remove it's repo when we are done
266
+
// so don't wait for graceful exit, just terminate the process
246
267
this.subprocess.kill('SIGKILL')
247
-
},this.opts.forceKillTimeout)
248
-
}
268
+
}else{
269
+
if(this.opts.forceKill!==false){
270
+
killTimeout=setTimeout(()=>{
271
+
// eslint-disable-next-line no-console
272
+
console.error(newError(`Timeout stopping ${this.opts.type} node after ${this.opts.forceKillTimeout}ms. Process ${this.subprocess.pid} will be force killed now.`))
273
+
this.subprocess.kill('SIGKILL')
274
+
},this.opts.forceKillTimeout)
275
+
}
249
276
250
-
try{
251
-
awaitthis.api.stop()
252
-
}catch(err){
253
-
if(!killed){
254
-
throwerr// if was killed then ignore error
277
+
this.subprocess.cancel()
255
278
}
256
279
257
-
daemonLog.info('Daemon was force killed')
258
-
}
280
+
// wait for the subprocess to exit and declare ourselves stopped
281
+
awaitwaitFor(()=>!this.started,{
282
+
timeout
283
+
})
259
284
260
-
clearTimeout(killTimeout)
261
-
this.subprocess.stderr.removeAllListeners()
262
-
this.subprocess.stdout.removeAllListeners()
263
-
this.started=false
285
+
clearTimeout(killTimeout)
286
+
287
+
if(this.disposable){
288
+
// wait for the cleanup routine to run after the subprocess has exited
0 commit comments