Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dgram: sync the old handle state to new handle #46041

Merged
merged 1 commit into from
Jan 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ function startListening(socket) {
function replaceHandle(self, newHandle) {
const state = self[kStateSymbol];
const oldHandle = state.handle;

// Sync the old handle state to new handle
if (!oldHandle.hasRef() && typeof newHandle.unref === 'function') {
newHandle.unref();
}
// Set up the handle that we got from primary.
newHandle.lookup = oldHandle.lookup;
newHandle.bind = oldHandle.bind;
Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-dgram-unref-in-cluster.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common');
const dgram = require('dgram');
const cluster = require('cluster');
const assert = require('assert');

if (common.isWindows)
common.skip('dgram clustering is currently not supported on Windows.');

if (cluster.isPrimary) {
cluster.fork();
} else {
const socket = dgram.createSocket('udp4');
socket.unref();
socket.bind();
socket.on('listening', common.mustCall(() => {
const sockets = process.getActiveResourcesInfo().filter((item) => {
return item === 'UDPWrap';
});
assert.ok(sockets.length === 0);
process.disconnect();
}));
}