-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dgram: remove listeners on bind error
This avoids piling up `'listening'` event listeners if `.bind()` fails repeatedly. Fixes: #30209 PR-URL: #30210 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
fd5fed1
commit 3d39be7
Showing
2 changed files
with
42 additions
and
2 deletions.
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
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,27 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const dgram = require('dgram'); | ||
|
||
// Regression test for https://github.com/nodejs/node/issues/30209 | ||
// No warning should be emitted when re-trying `.bind()` on UDP sockets | ||
// repeatedly. | ||
|
||
process.on('warning', common.mustNotCall()); | ||
|
||
const reservePortSocket = dgram.createSocket('udp4'); | ||
reservePortSocket.bind(() => { | ||
const { port } = reservePortSocket.address(); | ||
|
||
const newSocket = dgram.createSocket('udp4'); | ||
|
||
let errors = 0; | ||
newSocket.on('error', common.mustCall(() => { | ||
if (++errors < 20) { | ||
newSocket.bind(port, common.mustNotCall()); | ||
} else { | ||
newSocket.close(); | ||
reservePortSocket.close(); | ||
} | ||
}, 20)); | ||
newSocket.bind(port, common.mustNotCall()); | ||
}); |