This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.
Closed
Description
If you create a udp4 socket and send some data over it to an invalid hostname (as in the Coffee-Script example below), then the callback will be called to indicate that an error occurred. Unfortunately, the udp socket will ALSO throw a top-level exception which kills the entire app.
Sample:
socket = (require 'dgram').createSocket 'udp4'
#socket.on "error", (err) ->
# console.log "Error handler: #{err}"
buffer = new Buffer("foo")
callback = (err, bytes) ->
if err
console.log("Error sending: #{err}")
else
console.log("Sent #{bytes}")
socket.send(buffer, 0, buffer.length, 100, "asdkasd", callback)
Run with "coffee sample.coffee". You'll get the following output:
Error sending: Error: getaddrinfo ENOTFOUND
events.js:71
throw arguments[1]; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)
And the problem If you uncomment the two lines at the top, and define a "on error" handler, then the callback will be called with the error, and the error handler will also be called, and the program will not terminate (since the socket is never closed.)
I would expect that either the presence of a callback or a defined error handler would prevent killing the program, and not require both?