Repository navigation
Lost UDP datagrams when sending in socket.send callback #25646
Description
Activity
That's not unexpected and not a Node.js issue. UDP is lossy, unreliable. If you transmit faster than the operating system can send out the datagrams, or faster than the intermediate hops can retransmit them, some of them will end up being dropped.
If you have reason to believe it is a Node.js issue let me know but until then I'm closing this out.
- addedinvalidIssues and PRs that are invalid.Issues and PRs that are invalid.dgramIssues and PRs related to UDP and the dgram module.Issues and PRs related to UDP and the dgram module.
on Jan 23, 2019 This is a node bug.
Reacted by Andrew Hay Kurtz and Jacob BogersThis is still broken in node 12. I know UDP is lossy. That's not the problem. If this is the intended behavior then it needs to be documented because dropping back to the event queue in this situation isn't obvious.
Reacted by Jacob BogersYou're failing to make a case for why this should be a Node.js issue.
Let's try a slightly different way: as @bnoordhuis points out, the current dgram/udp stack in Node.js makes no guarantees that datagram sending is reliable. The code is working as intended. Making udp more reliable is possible, and if it's something that's important to you, a PR will always be considered. In the meantime, we are busy working to implement QUIC support that does add a layer of reliability on top of UDP. In the future, that may be worth exploring.
This is a node bug.
yeah, its a bug, we use
setTimeoutaswell to solve it,This is still broken in node 12. I know UDP is lossy. That's not the problem. If this is the intended behavior then it needs to be documented because dropping back to the event queue in this situation isn't obvious.
I tested your code on node 16, it is not an issue anymore, I think somewhere along they way it was solved (not tested on 13,14,15 versions)
Linux 4.4.0-17763-Microsoft #253-Microsoft x86_64 GNU/Linux
node versions tried: v8.15.0 v10.15.0 v11.7.0
Use this server or any tool you can listen to UDP with:
Run this to demonstrate the problem:
If I call socket.send from within its own callback, some UDP datagrams never show up at the destination. The workaround is to let the callback exit first. Here we see server output showing missing datagrams where we expect the log to finish up with "997, 998, 999".