Skip to content

Commit

Permalink
dgram: sync the old handle state to new handle
Browse files Browse the repository at this point in the history
  • Loading branch information
theanarkh committed Jan 1, 2023
1 parent 28fe494 commit 0d7e90c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/dgram.js
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
18 changes: 18 additions & 0 deletions test/parallel/test-dgram-unref-in-cluster.js
@@ -0,0 +1,18 @@
'use strict';
const common = require('../common');
const dgram = require('dgram');
const cluster = require('cluster');

// Test if the worker process exits.

if (cluster.isPrimary) {
cluster.fork();
} else {
const socket = dgram.createSocket('udp4');
socket.unref();
socket.bind();
socket.on('listening', common.mustCall(() => {
// Do not keep loop alive
process.channel.unref();
}));
}

0 comments on commit 0d7e90c

Please sign in to comment.