Skip to content

Commit

Permalink
test: handle zero-length udp datagram
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bnoordhuis committed Mar 7, 2024
1 parent ff95879 commit 41710bb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/test-udp-recv-in-a-row.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,15 @@ static void sv_recv_cb(uv_udp_t* handle,
const uv_buf_t* rcvbuf,
const struct sockaddr* addr,
unsigned flags) {
if (++ recv_cnt < N) {
ASSERT_EQ(sizeof(send_data), nread);
} else {
ASSERT_OK(nread);
}
/* |nread| can be zero when the kernel drops an incoming datagram after
* marking the file descriptor as readable but before libuv has a chance
* to receive it. Libuv still invokes the uv_udp_recv_cb callback to give
* back the memory from the uv_alloc_cb callback.
*
* See https://github.com/libuv/libuv/issues/4219.
*/
ASSERT_GE(nread, 0);
recv_cnt++;
}

static void check_cb(uv_check_t* handle) {
Expand Down

0 comments on commit 41710bb

Please sign in to comment.