Skip to content

Commit ea4be72

Browse files
apapirovskitargos
authored andcommitted
child_process: swallow errors in internal communication
Much like with NODE_HANDLE_ACK, the internal protocol for communication about the sent socket should not expose its errors to the users when those async calls are not initiated by them. PR-URL: #21108 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 0b0370f commit ea4be72

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

lib/internal/socket_list.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class SocketListSend extends EventEmitter {
1313
child.once('exit', () => this.emit('exit', this));
1414
}
1515

16-
_request(msg, cmd, callback) {
16+
_request(msg, cmd, swallowErrors, callback) {
1717
var self = this;
1818

1919
if (!this.child.connected) return onclose();
20-
this.child.send(msg);
20+
this.child._send(msg, undefined, swallowErrors);
2121

2222
function onclose() {
2323
self.child.removeListener('internalMessage', onreply);
@@ -40,14 +40,14 @@ class SocketListSend extends EventEmitter {
4040
this._request({
4141
cmd: 'NODE_SOCKET_NOTIFY_CLOSE',
4242
key: this.key
43-
}, 'NODE_SOCKET_ALL_CLOSED', callback);
43+
}, 'NODE_SOCKET_ALL_CLOSED', true, callback);
4444
}
4545

4646
getConnections(callback) {
4747
this._request({
4848
cmd: 'NODE_SOCKET_GET_COUNT',
4949
key: this.key
50-
}, 'NODE_SOCKET_COUNT', function(err, msg) {
50+
}, 'NODE_SOCKET_COUNT', false, function(err, msg) {
5151
if (err) return callback(err);
5252
callback(null, msg.count);
5353
});
@@ -67,10 +67,10 @@ class SocketListReceive extends EventEmitter {
6767
function onempty(self) {
6868
if (!self.child.connected) return;
6969

70-
self.child.send({
70+
self.child._send({
7171
cmd: 'NODE_SOCKET_ALL_CLOSED',
7272
key: self.key
73-
});
73+
}, undefined, true);
7474
}
7575

7676
this.child.on('internalMessage', (msg) => {
@@ -84,7 +84,7 @@ class SocketListReceive extends EventEmitter {
8484
this.once('empty', onempty);
8585
} else if (msg.cmd === 'NODE_SOCKET_GET_COUNT') {
8686
if (!this.child.connected) return;
87-
this.child.send({
87+
this.child._send({
8888
cmd: 'NODE_SOCKET_COUNT',
8989
key: this.key,
9090
count: this.connections

test/parallel/parallel.status

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ prefix parallel
77
[true] # This section applies to all platforms
88

99
[$system==win32]
10-
test-child-process-fork-net-socket: PASS,FLAKY
1110

1211
[$system==linux]
1312

test/parallel/test-internal-socket-list-receive.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const key = 'test-key';
1212
{
1313
const child = Object.assign(new EventEmitter(), {
1414
connected: false,
15-
send: common.mustNotCall()
15+
_send: common.mustNotCall()
1616
});
1717

1818
const list = new SocketListReceive(child, key);
@@ -24,7 +24,7 @@ const key = 'test-key';
2424
{
2525
const child = Object.assign(new EventEmitter(), {
2626
connected: true,
27-
send: common.mustCall((msg) => {
27+
_send: common.mustCall((msg) => {
2828
assert.strictEqual(msg.cmd, 'NODE_SOCKET_ALL_CLOSED');
2929
assert.strictEqual(msg.key, key);
3030
})
@@ -38,7 +38,7 @@ const key = 'test-key';
3838
{
3939
const child = Object.assign(new EventEmitter(), {
4040
connected: true,
41-
send: common.mustCall((msg) => {
41+
_send: common.mustCall((msg) => {
4242
assert.strictEqual(msg.cmd, 'NODE_SOCKET_COUNT');
4343
assert.strictEqual(msg.key, key);
4444
assert.strictEqual(msg.count, 0);

test/parallel/test-internal-socket-list-send.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const key = 'test-key';
1616

1717
const list = new SocketListSend(child, 'test');
1818

19-
list._request('msg', 'cmd', common.mustCall((err) => {
19+
list._request('msg', 'cmd', false, common.mustCall((err) => {
2020
common.expectsError({
2121
code: 'ERR_CHILD_CLOSED_BEFORE_REPLY',
2222
type: Error,
@@ -30,7 +30,7 @@ const key = 'test-key';
3030
{
3131
const child = Object.assign(new EventEmitter(), {
3232
connected: true,
33-
send: function(msg) {
33+
_send: function(msg) {
3434
process.nextTick(() =>
3535
this.emit('internalMessage', { key, cmd: 'cmd' })
3636
);
@@ -39,7 +39,7 @@ const key = 'test-key';
3939

4040
const list = new SocketListSend(child, key);
4141

42-
list._request('msg', 'cmd', common.mustCall((err, msg) => {
42+
list._request('msg', 'cmd', false, common.mustCall((err, msg) => {
4343
assert.strictEqual(err, null);
4444
assert.strictEqual(msg.cmd, 'cmd');
4545
assert.strictEqual(msg.key, key);
@@ -53,12 +53,12 @@ const key = 'test-key';
5353
{
5454
const child = Object.assign(new EventEmitter(), {
5555
connected: true,
56-
send: function(msg) { process.nextTick(() => this.emit('disconnect')); }
56+
_send: function(msg) { process.nextTick(() => this.emit('disconnect')); }
5757
});
5858

5959
const list = new SocketListSend(child, key);
6060

61-
list._request('msg', 'cmd', common.mustCall((err) => {
61+
list._request('msg', 'cmd', false, common.mustCall((err) => {
6262
common.expectsError({
6363
code: 'ERR_CHILD_CLOSED_BEFORE_REPLY',
6464
type: Error,
@@ -73,7 +73,7 @@ const key = 'test-key';
7373
{
7474
const child = Object.assign(new EventEmitter(), {
7575
connected: true,
76-
send: function(msg) {
76+
_send: function(msg) {
7777
assert.strictEqual(msg.cmd, 'NODE_SOCKET_NOTIFY_CLOSE');
7878
assert.strictEqual(msg.key, key);
7979
process.nextTick(() =>
@@ -98,7 +98,7 @@ const key = 'test-key';
9898
const count = 1;
9999
const child = Object.assign(new EventEmitter(), {
100100
connected: true,
101-
send: function(msg) {
101+
_send: function(msg) {
102102
assert.strictEqual(msg.cmd, 'NODE_SOCKET_GET_COUNT');
103103
assert.strictEqual(msg.key, key);
104104
process.nextTick(() =>
@@ -127,7 +127,7 @@ const key = 'test-key';
127127
const count = 1;
128128
const child = Object.assign(new EventEmitter(), {
129129
connected: true,
130-
send: function() {
130+
_send: function() {
131131
process.nextTick(() => {
132132
this.emit('disconnect');
133133
this.emit('internalMessage', { key, count, cmd: 'NODE_SOCKET_COUNT' });

0 commit comments

Comments
 (0)