Skip to content

dgram: do not emit error for failed DNS lookups in send()

Rodrigo Muino Tomonari requested to merge github/fork/mcollina/dgram-dns into master

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, in a way that it behaves as users would expect to. I would recommend to get this in for the upcoming 3.0.0 release, and not for the 2.x series.

In the currently releases, in order to wrap a udp socket one has to write this error handling code:

sock.on('error', function(err) {
  // we are skipping DNS errors
  if(err.code !== 'ENOTFOUND')
    that.emit('error', err)
})

Which is ugly, undocumented and error-prone. This PR resolves this problem.

This is based of @chrisdickinson joyent/node#7738. Discussion in joyent/node#4846.

cc @sam-github @bnoordhuis @jasnell

Merge request reports

Loading