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: do not call callback if socket is closed #52829

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

Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-dgram-bind-socket-close-before-cluster-reply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
const common = require('../common');
const dgram = require('dgram');
const cluster = require('cluster');

if (cluster.isPrimary) {
cluster.fork();
} else {
// When the socket attempts to bind, it requests a handle from the cluster.
// Force the cluster to send back an error code.
const socket = dgram.createSocket('udp4');
cluster._getServer = function(self, options, callback) {
socket.close(() => { cluster.worker.disconnect(); });
callback(-1);
};
theanarkh marked this conversation as resolved.
Show resolved Hide resolved
socket.on('error', common.mustNotCall());
socket.bind();
}