Skip to content

Commit 0d7e90c

Browse files
committed
dgram: sync the old handle state to new handle
1 parent 28fe494 commit 0d7e90c

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/dgram.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ function startListening(socket) {
184184
function replaceHandle(self, newHandle) {
185185
const state = self[kStateSymbol];
186186
const oldHandle = state.handle;
187-
187+
// Sync the old handle state to new handle
188+
if (!oldHandle.hasRef() && typeof newHandle.unref === 'function') {
189+
newHandle.unref();
190+
}
188191
// Set up the handle that we got from primary.
189192
newHandle.lookup = oldHandle.lookup;
190193
newHandle.bind = oldHandle.bind;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use strict';
2+
const common = require('../common');
3+
const dgram = require('dgram');
4+
const cluster = require('cluster');
5+
6+
// Test if the worker process exits.
7+
8+
if (cluster.isPrimary) {
9+
cluster.fork();
10+
} else {
11+
const socket = dgram.createSocket('udp4');
12+
socket.unref();
13+
socket.bind();
14+
socket.on('listening', common.mustCall(() => {
15+
// Do not keep loop alive
16+
process.channel.unref();
17+
}));
18+
}

0 commit comments

Comments
 (0)