Skip to content

Commit f05baff

Browse files
authored
lib: do not call callback if socket is closed
PR-URL: #52829 Reviewed-By: Matteo Collina <[email protected]>
1 parent 7e6d92c commit f05baff

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/dgram.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,10 @@ function bindServerHandle(self, options, errCb) {
219219
const state = self[kStateSymbol];
220220
cluster._getServer(self, options, (err, handle) => {
221221
if (err) {
222-
errCb(err);
222+
// Do not call callback if socket is closed
223+
if (state.handle) {
224+
errCb(err);
225+
}
223226
return;
224227
}
225228

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+
if (cluster.isPrimary) {
7+
cluster.fork();
8+
} else {
9+
// When the socket attempts to bind, it requests a handle from the cluster.
10+
// Force the cluster to send back an error code.
11+
const socket = dgram.createSocket('udp4');
12+
cluster._getServer = function(self, options, callback) {
13+
socket.close(() => { cluster.worker.disconnect(); });
14+
callback(-1);
15+
};
16+
socket.on('error', common.mustNotCall());
17+
socket.bind();
18+
}

0 commit comments

Comments
 (0)