-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dgram: do not emit error for failed DNS lookups in send()
Modifies the dgram send() method to not emit errors when a DNS lookup fails if there is no callback. Given that the same UDP socket can be used to send messages to different hosts, the socket can be reused even if one of those send() fails. This slightly changes the behavior of a stable API, so that it behaves as users would expect to. This is based of @chrisdickinson nodejs/node-v0.x-archive#7738. Discussion in nodejs/node-v0.x-archive#4846.
- Loading branch information
Showing
3 changed files
with
36 additions
and
59 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,35 @@ | ||
'use strict'; | ||
var common = require('../common'); | ||
var assert = require('assert'); | ||
var dgram = require('dgram'); | ||
var dns = require('dns'); | ||
|
||
var socket = dgram.createSocket('udp4'); | ||
var buffer = new Buffer('gary busey'); | ||
|
||
dns.setServers([]); | ||
|
||
socket.once('error', onEvent); | ||
|
||
// assert that: | ||
// * callbacks act as "error" listeners if given. | ||
// * error is never emitter for missing dns entries | ||
// if a callback that handles error is present | ||
// * error is emitted if a callback with no argument is passed | ||
socket.send(buffer, 0, buffer.length, 100, 'dne.example.com', callbackOnly); | ||
|
||
function callbackOnly(err) { | ||
assert.ok(err); | ||
socket.removeListener('error', onEvent); | ||
socket.on('error', onError); | ||
socket.send(buffer, 0, buffer.length, 100, 'dne.example.com'); | ||
} | ||
|
||
function onEvent(err) { | ||
assert.fail('Error should not be emitted if there is callback'); | ||
} | ||
|
||
function onError(err) { | ||
assert.ok(err); | ||
socket.close(); | ||
} |
This file was deleted.
Oops, something went wrong.