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 35e3298

Browse filesBrowse files
TrottMyles Borins
authored andcommitted
child_process: guard against race condition
It is possible that the internal hnadleMessage() might try to send to a channel that has been closed. The result can be an AssertionError. Guard against this. Fixes: #4205 PR-URL: #4418 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
1 parent 41fcda8 commit 35e3298
Copy full SHA for 35e3298

File tree

Expand file treeCollapse file tree

2 files changed

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

2 files changed

+36
-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
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ function setupChannel(target, channel) {
675675

676676
const INTERNAL_PREFIX = 'NODE_';
677677
function handleMessage(target, message, handle) {
678+
if (!target._channel)
679+
return;
680+
678681
var eventName = 'message';
679682
if (message !== null &&
680683
typeof message === 'object' &&
Collapse file
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
'use strict';
2+
3+
// This code triggers an AssertionError on Linux in Node.js 5.3.0 and earlier.
4+
// Ref: https://github.com/nodejs/node/issues/4205
5+
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const net = require('net');
9+
const cluster = require('cluster');
10+
cluster.schedulingPolicy = cluster.SCHED_NONE;
11+
12+
if (cluster.isMaster) {
13+
var worker1, worker2;
14+
15+
worker1 = cluster.fork();
16+
worker1.on('message', common.mustCall(function() {
17+
worker2 = cluster.fork();
18+
worker1.disconnect();
19+
worker2.on('online', common.mustCall(worker2.disconnect));
20+
}));
21+
22+
cluster.on('exit', function(worker, code) {
23+
assert.strictEqual(code, 0, 'worker exited with error');
24+
});
25+
26+
return;
27+
}
28+
29+
var server = net.createServer();
30+
31+
server.listen(common.PORT, function() {
32+
process.send('listening');
33+
});

0 commit comments

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