-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
node 4.1.2 on OS X: child_process emits exit/close to wrong instance #3236
Comments
Hm, I cannot reproduce. I have this: 'use strict'
const spawn = require('child_process').spawn
function ChildProcess(desc, exe, args, cb) {
this.desc = desc
this.exited = false
var self = this
this.process = spawn(exe, args)
.on('exit', function(code, signal) {
self.exited = true
console.log(self.desc, 'exit', code, signal)
})
.on('close', function(code, signal) {
self.exited = true
console.log(self.desc, 'close', code, signal)
if (cb) cb(code, signal)
})
.on('error', function(err) {
console.log(self.desc, 'error', err)
})
}
ChildProcess.prototype.kill = function(signal) {
if (this.exited)
return
console.log(this.desc, 'kill', signal)
this.process.kill(signal)
}
var p1 = new ChildProcess('p1', '/bin/sleep', ['11'], function(code, signal) {
console.log('p1 <=', code, signal)
})
var p2 = new ChildProcess('p2', '/bin/sleep', ['12'], function(code, signal) {
console.log('p2 <=', code, signal)
})
setTimeout(function() {
p2.kill('SIGTERM')
p1.kill('SIGTERM')
}, 1000) It looks like you have some global variables in that code, which could be causing an issue? |
With the above, I get the following output:
|
My fault. ( var self = this ) ... |
You’re right. Thanks a thousand times for the ‘use strict’ info… Shame about me… Michael
|
node --version => v4.1.2
uname -a => Darwin xxx 15.0.0 Darwin Kernel Version 15.0.0: Wed Aug 26 16:57:32 PDT 2015; root:xnu-3247.1.106~1/RELEASE_X86_64 x86_64
only the last spawned child_process instance will get the emitted 'exit' and 'close' events, but this also for OTHER instances too...
100% reproducable with this source:
Output is
The text was updated successfully, but these errors were encountered: