Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 798dad2

Browse filesBrowse files
indutnyFishrock123
authored andcommitted
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 <trev.norris@gmail.com>
1 parent 039f73f commit 798dad2
Copy full SHA for 798dad2

File tree

Expand file treeCollapse file tree

2 files changed

+41
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+41
-0
lines changed
Open diff view settings
Collapse file

‎lib/internal/child_process.js‎

Copy file name to clipboardExpand all lines: lib/internal/child_process.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ function setupChannel(target, channel) {
449449
target.disconnect();
450450
channel.onread = nop;
451451
channel.close();
452+
target._channel = null;
452453
maybeClose(target);
453454
}
454455
};
Collapse file
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
6+
const cluster = require('cluster');
7+
const net = require('net');
8+
const util = require('util');
9+
10+
if (!cluster.isMaster) {
11+
// Exit on first received handle to leave the queue non-empty in master
12+
process.on('message', function() {
13+
process.exit(1);
14+
});
15+
return;
16+
}
17+
18+
var server = net.createServer(function(s) {
19+
setTimeout(function() {
20+
s.destroy();
21+
}, 100);
22+
}).listen(common.PORT, function() {
23+
var worker = cluster.fork();
24+
25+
function send(callback) {
26+
var s = net.connect(common.PORT, function() {
27+
worker.send({}, s, callback);
28+
});
29+
}
30+
31+
worker.process.once('close', common.mustCall(function() {
32+
// Otherwise the crash on `_channel.fd` access may happen
33+
assert(worker.process._channel === null);
34+
server.close();
35+
}));
36+
37+
// Queue up several handles, to make `process.disconnect()` wait
38+
for (var i = 0; i < 100; i++)
39+
send();
40+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.