Skip to content

Commit 38dd506

Browse files
theanarkhRafaelGSS
authored andcommitted
dgram: sync the old handle state to new handle
PR-URL: #46041 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Paolo Insogna <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Juan José Arboleda <[email protected]>
1 parent a266dac commit 38dd506

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/dgram.js

+4-1
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;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
'use strict';
2+
const common = require('../common');
3+
const dgram = require('dgram');
4+
const cluster = require('cluster');
5+
const assert = require('assert');
6+
7+
if (common.isWindows)
8+
common.skip('dgram clustering is currently not supported on Windows.');
9+
10+
if (cluster.isPrimary) {
11+
cluster.fork();
12+
} else {
13+
const socket = dgram.createSocket('udp4');
14+
socket.unref();
15+
socket.bind();
16+
socket.on('listening', common.mustCall(() => {
17+
const sockets = process.getActiveResourcesInfo().filter((item) => {
18+
return item === 'UDPWrap';
19+
});
20+
assert.ok(sockets.length === 0);
21+
process.disconnect();
22+
}));
23+
}

0 commit comments

Comments
 (0)