Skip to content

Commit

Permalink
fix(shutdown): fixed bugs in stopDaemon
Browse files Browse the repository at this point in the history
- bug1: local var for the closure (this.subprocess set to null)
- bug2: order problem: should set .on('close') handler before .kill()
  • Loading branch information
jbenet committed Sep 16, 2016
1 parent 3c50894 commit d6ad480
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,18 +151,19 @@ module.exports = class Node {
if (!done) done = () => {}
if (!this.subprocess) return done(null)

this.subprocess.kill('SIGTERM')

// need a local var for the closure, as we clear the var.
const subprocess = this.subprocess
const timeout = setTimeout(() => {
this.subprocess.kill('SIGKILL')
subprocess.kill('SIGKILL')
done(null)
}, GRACE_PERIOD)

this.subprocess.on('close', () => {
subprocess.on('close', () => {
clearTimeout(timeout)
done(null)
})

subprocess.kill('SIGTERM')
this.subprocess = null
}

Expand Down

0 comments on commit d6ad480

Please sign in to comment.