-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: do not call callback if socket is closed
PR-URL: #52829 Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
2 changed files
with
22 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
test/parallel/test-dgram-bind-socket-close-before-cluster-reply.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
socket.on('error', common.mustNotCall()); | ||
socket.bind(); | ||
} |