-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
UdpSocket: recv() and recv_from() behave differently for zero sized buffers #149392
Copy link
Copy link
Closed
Closed
Copy link
Labels
A-error-handlingArea: Error handlingArea: Error handlingA-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.Category: This is a bug.S-waiting-on-t-libs-apiStatus: Awaiting decision from T-libs-apiStatus: Awaiting decision from T-libs-apiT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-error-handlingArea: Error handlingArea: Error handlingA-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-bugCategory: This is a bug.Category: This is a bug.S-waiting-on-t-libs-apiStatus: Awaiting decision from T-libs-apiStatus: Awaiting decision from T-libs-apiT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
With a zero length buffer UdpSocket recv() behaves differently from recv_from().
(Only tested on MacOS M1 processor)
recv_from() returns the following error:
Err(Error { kind: InvalidInput, message: "invalid argument" })
recv() instantly returns with Ok(0), even though no UDP packet has been received
I would expect both to return Err(Error { kind: InvalidInput, message: "invalid argument" })
Importance
The api is different for similar functions, I believe they should behave the same way.
I encountered the bug when using
let mut buf=Vec::with_capacity(MTU);
Which could be an easy to overlook mistake.
Also recv() is returning even though no UDP packet has been received, in my case this led to a thread consuming 100% of a CPU.
Test case:
Expected
I expected to see this happen:
I would expect both to return Err(Error { kind: InvalidInput, message: "invalid argument" })
I would not expect that recv instantly return an Ok(0) even though no UDP packet has been received.
Actual
Instead, this happened:
Meta
rustc --version --verbose:OS uname -aRelated
Possibly related #55794 #123222