Skip to content

Commit 23f086c

Browse files
theanarkhmarco-ippolito
authored andcommitted
lib: do not call callback if socket is closed
PR-URL: #52829 Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 3b79e9c commit 23f086c

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
@@ -221,7 +221,10 @@ function bindServerHandle(self, options, errCb) {
221221
const state = self[kStateSymbol];
222222
cluster._getServer(self, options, (err, handle) => {
223223
if (err) {
224-
errCb(err);
224+
// Do not call callback if socket is closed
225+
if (state.handle) {
226+
errCb(err);
227+
}
225228
return;
226229
}
227230

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)