Skip to content

Commit 9c31026

Browse files
test: deflake test-permission-net-udp-handle
Sending a dgram socket over IPC duplicates the handle instead of moving it: `dgram.Socket` has no `postSend` in the child_process conversion table, and `bind()` calls `recvStart()` unconditionally, so the parent copy keeps consuming datagrams after the child adopts the handle. Both sockets then compete for every packet. In local testing the parent consumed 110 consecutive packets before the child received one; on a slower machine the race can keep the child from receiving anything before the test timeout, which is how this failed in CI. Close the parent copy as soon as the child reports it is receiving, so the child is the only reader by the time the first datagram is sent. Signed-off-by: Christian Aurich <christian.aurichzm@gmail.com>
1 parent 761e49e commit 9c31026

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎test/parallel/test-permission-net-udp-handle.js‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ if (mode === 'ipc-denied') {
6060
const droppedSocket = dgram.createSocket('udp4');
6161
const sender = dgram.createSocket('udp4');
6262
droppedSocket.bind(0, '127.0.0.1', common.mustCall(() => {
63+
const { port } = droppedSocket.address();
6364
const child = fork(__filename, ['ipc-drop'], {
6465
execArgv: [
6566
'--permission',
@@ -73,15 +74,17 @@ if (mode === 'ipc-denied') {
7374
if (message === 'ready') {
7475
child.send('socket', droppedSocket);
7576
} else if (message === 'receiving') {
76-
const { port } = droppedSocket.address();
77+
// Sending the socket over IPC keeps this copy open and receiving, so
78+
// both ends compete for incoming datagrams. Stop receiving before the
79+
// first one goes out.
80+
droppedSocket.close();
7781
timer = setInterval(() => {
7882
sender.send('after-drop', port, '127.0.0.1');
7983
}, 10);
8084
} else {
8185
assert.strictEqual(message, 'received');
8286
clearInterval(timer);
8387
sender.close();
84-
droppedSocket.close();
8588
child.disconnect();
8689
}
8790
}, 3));

0 commit comments

Comments
 (0)