Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

dgram: make .send cb act as an "error" event handler. #7738

Closed

Conversation

chrisdickinson
Copy link

This allows users to provide a callback that handles potential
errors resulting from a socket.send call. The original behavior
of emitting the error event on the socket is preserved.

Fixes #4846.


if (self.listeners('error').length) {
self.emit('error', ex);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention is to drop the quotes for one-line if statements.

@bnoordhuis
Copy link
Member

LGTM, no comments.

An observation about the review process: it's usually easier when you push fix-up commits to your branch rather than squashing straight away.

When you squash, GH tends to hide comments from previous review rounds and that sometimes makes it difficult to track the flow of the discussion. Once the review is done however, you can squash and land at will.

@sam-github
Copy link

Changes API, but introduces no documentation!

callback(ex);

if (self.listeners('error').length)
self.emit('error', ex);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this redundant, can't we just rely upon the return value from self.emit to determine if this was handled?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we emit and there's no error listener, the error will be thrown. This check explicitly prevents that if there's a callback.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right -- that part of the api -- sigh sorry

@tjfontaine
Copy link

I concur with @sam-github that we should clarify here where and when errors will be handled in this way

@trevnorris
Copy link

Just to clarify, missing changes to the docs is what's holding up this PR?

This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes nodejs#4846.
@mcollina
Copy link
Member

Putting some more though on this one, I still think that if there is a callback, then the error should not be emitted, as they will have to 'trap' that error and ignore it, causing the exact same issue described above.
A safe way to keep backward compatibility might be to check the callback.length, as if it has an argument then we can assume the application is going to handle the error. What do you think?

@sam-github
Copy link

I think we should break compatibility in node v3.x, or else have a different send that does the right thing.

@mcollina
Copy link
Member

I agree with @sam-github. Do you think it might make sense to send a PR to io.js, or I should wait after the merge happens?

@sam-github
Copy link

I don't think its worth waiting, and the io.js repo is going to move, to my knowledge, to the new org.

mcollina added a commit to mcollina/node that referenced this pull request May 26, 2015
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.
mcollina added a commit to mcollina/node that referenced this pull request May 26, 2015
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.
mcollina added a commit to mcollina/node that referenced this pull request May 27, 2015
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.
mcollina added a commit to mcollina/node that referenced this pull request May 27, 2015
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.
chrisdickinson added a commit to nodejs/node that referenced this pull request Jun 5, 2015
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
cjihrig pushed a commit to nodejs/node that referenced this pull request Jun 5, 2015
Modifies the dgram send() method to not emit errors when a DNS
lookup fails if there is a 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 on nodejs/node-v0.x-archive#7738, which
landed in 77266d7.

Fixes: nodejs/node-v0.x-archive#4846
Refs: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@cjihrig
Copy link

cjihrig commented Jun 5, 2015

Closing this. The fix can be back ported from nodejs/node@77266d7 and nodejs/node@90daf87.

@cjihrig cjihrig closed this Jun 5, 2015
chrisdickinson added a commit to nodejs/node that referenced this pull request Jun 17, 2015
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
chrisdickinson pushed a commit to nodejs/node that referenced this pull request Jun 17, 2015
Modifies the dgram send() method to not emit errors when a DNS
lookup fails if there is a 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 on nodejs/node-v0.x-archive#7738, which
landed in 77266d7.

Fixes: nodejs/node-v0.x-archive#4846
Refs: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
chrisdickinson added a commit to nodejs/node that referenced this pull request Jul 22, 2015
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
rvagg pushed a commit to nodejs/node that referenced this pull request Jul 22, 2015
Modifies the dgram send() method to not emit errors when a DNS
lookup fails if there is a 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 on nodejs/node-v0.x-archive#7738, which
landed in 77266d7.

Fixes: nodejs/node-v0.x-archive#4846
Refs: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
chrisdickinson added a commit to nodejs/node that referenced this pull request Jul 24, 2015
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
rvagg pushed a commit to nodejs/node that referenced this pull request Jul 24, 2015
Modifies the dgram send() method to not emit errors when a DNS
lookup fails if there is a 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 on nodejs/node-v0.x-archive#7738, which
landed in 77266d7.

Fixes: nodejs/node-v0.x-archive#4846
Refs: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
chrisdickinson added a commit to nodejs/node that referenced this pull request Jul 30, 2015
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
rvagg pushed a commit to nodejs/node that referenced this pull request Jul 30, 2015
Modifies the dgram send() method to not emit errors when a DNS
lookup fails if there is a 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 on nodejs/node-v0.x-archive#7738, which
landed in 77266d7.

Fixes: nodejs/node-v0.x-archive#4846
Refs: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
chrisdickinson added a commit to nodejs/node that referenced this pull request Aug 1, 2015
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
rvagg pushed a commit to nodejs/node that referenced this pull request Aug 1, 2015
Modifies the dgram send() method to not emit errors when a DNS
lookup fails if there is a 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 on nodejs/node-v0.x-archive#7738, which
landed in 77266d7.

Fixes: nodejs/node-v0.x-archive#4846
Refs: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
chrisdickinson added a commit to nodejs/node that referenced this pull request Aug 3, 2015
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
rvagg pushed a commit to nodejs/node that referenced this pull request Aug 3, 2015
Modifies the dgram send() method to not emit errors when a DNS
lookup fails if there is a 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 on nodejs/node-v0.x-archive#7738, which
landed in 77266d7.

Fixes: nodejs/node-v0.x-archive#4846
Refs: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
chrisdickinson added a commit to nodejs/node that referenced this pull request Aug 4, 2015
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
rvagg pushed a commit to nodejs/node that referenced this pull request Aug 4, 2015
Modifies the dgram send() method to not emit errors when a DNS
lookup fails if there is a 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 on nodejs/node-v0.x-archive#7738, which
landed in 77266d7.

Fixes: nodejs/node-v0.x-archive#4846
Refs: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
chrisdickinson added a commit to nodejs/node that referenced this pull request Aug 4, 2015
This allows users to provide a callback that handles potential
errors resulting from a `socket.send` call. The original behavior
of emitting the error event on the socket is preserved.

Fixes: nodejs/node-v0.x-archive#4846
PR-URL: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
rvagg pushed a commit to nodejs/node that referenced this pull request Aug 4, 2015
Modifies the dgram send() method to not emit errors when a DNS
lookup fails if there is a 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 on nodejs/node-v0.x-archive#7738, which
landed in 77266d7.

Fixes: nodejs/node-v0.x-archive#4846
Refs: nodejs/node-v0.x-archive#7738
PR-URL: #1796
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants