Skip to content

Commit 9aeee94

Browse files
committed
lib: do not call callback if socket is closed
1 parent 4e9ce7c commit 9aeee94

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/dgram.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ 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+
state.handle && errCb(err);
225226
return;
226227
}
227228

Lines changed: 18 additions & 0 deletions
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)