Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: handle zero-length udp datagram #4344

Open
wants to merge 1 commit into
base: v1.x
Choose a base branch
from

Conversation

bnoordhuis
Copy link
Member

Under rare but benign circumstances, incoming datagrams are dropped by the operating system after libuv has been notified of their arrival but before it has had a chance to receive them.

Fixes: #4219

*
* See https://github.com/libuv/libuv/issues/4219.
*/
ASSERT_GE(nread, 0);
Copy link
Member

@vtjnash vtjnash Mar 7, 2024

Choose a reason for hiding this comment

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

I think it would be better to be exact here:

Suggested change
ASSERT_GE(nread, 0);
if (nread) ASSERT_EQ(nread, sizeof(send_data));

Under rare but benign circumstances, incoming datagrams are dropped by
the operating system after libuv has been notified of their arrival but
before libuv has had a chance to receive them.

Fixes: libuv#4219
@@ -63,9 +68,11 @@ static void check_cb(uv_check_t* handle) {
/**
* sv_recv_cb() is called with nread set to zero to indicate
* there is no more udp packet in the kernel, so the actual
* recv_cnt is one larger than N.
* recv_cnt is up to one larger than N. UDP being what it is,
* packets can get dropped so don't assume an exact count.
Copy link
Member Author

Choose a reason for hiding this comment

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

@vtjnash after looking at the code some more, I came the conclusion that the "is equal to N+1" check is wrong because any number of packets can get dropped. Even assuming a single packet makes it through is already a shaky assumption, just one that is true most of the time.

Copy link
Member

Choose a reason for hiding this comment

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

IIUC, the kernel does end up guaranteeing reliable UDP delivery to localhost. It is sort of by-accident, but it would be more work for it to discard messages because it goes through loopback directly instead of the making a whole roundtrip through the hardware.

Copy link
Member Author

Choose a reason for hiding this comment

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

Linux maybe but XNU? The CI failures are on macos buildbots.

FWIW, I can sort of reproduce it on Linux with a traffic-shaped device but at that point it's not really localhost traffic anymore so maybe not completely apples to apples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test: flaky test udp_recv_in_a_row
2 participants