-
Notifications
You must be signed in to change notification settings - Fork 61
Graceful stop #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Graceful stop #205
Changes from 16 commits
00958a7
ec58831
1db2ae4
6ecc02a
252e1d5
c3315ac
67a2041
8cd5abe
b1dc8ee
4f0c14d
3b32c03
2aec828
22c4ae9
74f6dc8
a5d0ec5
b3444f8
162ffb8
36fbb7a
5fc58bb
b1f5538
a61fa50
2d3cf40
3ffcee3
4ad247b
36aa183
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,10 +65,14 @@ class FactoryInProc { | |
| callback = options | ||
| options = {} | ||
| } | ||
| const IPFS = this.exec | ||
| new IPFS(options).version((err, _version) => { | ||
| if (err) { callback(err) } | ||
| callback(null, _version) | ||
|
|
||
| const IPFS = this.exec // otherwise lint barfs | ||
| const ipfs = new IPFS(options) | ||
| ipfs.once('ready', () => { | ||
| ipfs.version((err, _version) => { | ||
| if (err) { callback(err) } | ||
| callback(null, _version) | ||
| }) | ||
|
||
| }) | ||
| } | ||
|
|
||
|
|
@@ -129,15 +133,16 @@ class FactoryInProc { | |
| } | ||
|
|
||
| const node = new Node(options) | ||
|
|
||
| series([ | ||
| (cb) => options.init | ||
| ? node.init(cb) | ||
| : cb(), | ||
| (cb) => options.start | ||
| ? node.start(options.args, cb) | ||
| : cb() | ||
| ], (err) => callback(err, node)) | ||
| node.exec.once('ready', () => { | ||
|
||
| series([ | ||
| (cb) => options.init | ||
| ? node.init(cb) | ||
| : cb(), | ||
| (cb) => options.start | ||
| ? node.start(options.args, cb) | ||
| : cb() | ||
| ], (err) => callback(err, node)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,36 +270,40 @@ class Daemon { | |
| /** | ||
| * Kill the `ipfs daemon` process. | ||
| * | ||
| * First `SIGTERM` is sent, after 10.5 seconds `SIGKILL` is sent | ||
| * if the process hasn't exited yet. | ||
| * If the HTTP API is established, then send 'shutdown' command; otherwise, | ||
| * process.kill(`SIGTERM`) is used. In either case, if the process | ||
| * does not exit after 10.5 seconds then a `SIGKILL` is used. | ||
| * | ||
| * @param {function()} callback - Called when the process was killed. | ||
| * @returns {undefined} | ||
| */ | ||
| killProcess (callback) { | ||
| // need a local var for the closure, as we clear the var. | ||
| const self = this | ||
|
||
| const subprocess = this.subprocess | ||
| const timeout = setTimeout(() => { | ||
| log('kill timeout, using SIGKILL', subprocess.pid) | ||
| subprocess.kill('SIGKILL') | ||
| callback() | ||
| }, GRACE_PERIOD) | ||
|
|
||
| const disposable = this.disposable | ||
| const clean = this.cleanup.bind(this) | ||
| subprocess.once('close', () => { | ||
| subprocess.once('exit', () => { | ||
| log('killed', subprocess.pid) | ||
| clearTimeout(timeout) | ||
| this.subprocess = null | ||
| this._started = false | ||
| if (disposable) { | ||
| return clean(callback) | ||
| self.subprocess = null | ||
| self._started = false | ||
| if (self.disposable) { | ||
| return self.cleanup(callback) | ||
| } | ||
| callback() | ||
| setImmediate(callback) | ||
| }) | ||
|
|
||
| log('killing', subprocess.pid) | ||
| subprocess.kill('SIGTERM') | ||
| if (this.api) { | ||
| log('kill via api', subprocess.pid) | ||
| this.api.shutdown(() => null) | ||
| } else { | ||
| log('killing', subprocess.pid) | ||
| subprocess.kill('SIGTERM') | ||
| } | ||
| this.subprocess = null | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs a return. Otherwise chaos will happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, extremely bad code!!!