-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process:
null
channel handle on close
`HandleWrap::OnClose` destroys the underlying C++ object and null's the internal field pointer to it. Therefore there should be no references to the wrapping JavaScript object. `null` the process' `_channel` field right after closing it, to ensure no crashes will happen. Fix: #2847 PR-URL: #3041 Reviewed-By: Trevor Norris <[email protected]>
- Loading branch information
1 parent
039f73f
commit 798dad2
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const cluster = require('cluster'); | ||
const net = require('net'); | ||
const util = require('util'); | ||
|
||
if (!cluster.isMaster) { | ||
// Exit on first received handle to leave the queue non-empty in master | ||
process.on('message', function() { | ||
process.exit(1); | ||
}); | ||
return; | ||
} | ||
|
||
var server = net.createServer(function(s) { | ||
setTimeout(function() { | ||
s.destroy(); | ||
}, 100); | ||
}).listen(common.PORT, function() { | ||
var worker = cluster.fork(); | ||
|
||
function send(callback) { | ||
var s = net.connect(common.PORT, function() { | ||
worker.send({}, s, callback); | ||
}); | ||
} | ||
|
||
worker.process.once('close', common.mustCall(function() { | ||
// Otherwise the crash on `_channel.fd` access may happen | ||
assert(worker.process._channel === null); | ||
server.close(); | ||
})); | ||
|
||
// Queue up several handles, to make `process.disconnect()` wait | ||
for (var i = 0; i < 100; i++) | ||
send(); | ||
}); |