-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
net: UDPConn.ReadFrom returns error for oversized datagram on Windows #14074
Comments
I don't think it's worth to hide error messages from the platform. Also I don't think it's a temporary error. I personally hope to leave this as it is. Because it is application responsibility to validate application-level packet integrity when the application uses UDP-like datagram protocols.
FWIW, you may find it inconsistent to read a UDP datagram with zero-sized payload between platforms and/or kernel versions. |
I would prefer to be consistent and hide the error on Windows. |
I'm not fine hiding errors, but feel configuring MSG_PARTIAL for WSARecv on UDP might be a compromise. Even in that case please make sure the behavior is consistent on both Read/Write-like generic ops and Read{From,Msg}/Write{To,Msg}-like specific ops between platforms. |
I'm not proposing hiding all errors. Just this specific one. If there's a flag to get unixy semantics, that works too. |
Can we at least make it return non-zero n? The data is written to the buffer after all. |
Sounds reasonable to me. @fjl you want to send change when Go tree opens for go1.7 development? Thank you. Alex |
Yes, I'll send a CL then. |
I think it is fine for someone to send a CL making this case return n, err instead of 0, err. |
Change https://golang.org/cl/92475 mentions this issue: |
Just sent a CL to return |
@m4ns0ur your CL 92475 is changing net.UDPConn.ReadFrom to return "correct read data size" when the function returns error. When I use any Go function, I expect returned values to be meaningless if error is returned. If returned values are meaningful while error is not nil, that is explicitly documented - for example io.Reader.Read function. Where does net.UDPConn.ReadFrom documentation describes how to use returned values when it returns error? Alex |
@alexbrainman it makes sense, thanks for the tip. Will update the CL. |
I haven't look at your CL yet but please don't forget to consider that;
|
On all UNIXy platforms I've tried, ReadFrom(buf) consistently returns a nil error
and n == len(buf) when a datagram larger than buf arrives. Excess data is discarded
silently. On Windows, ReadFrom returns n == 0 and error WSAEMSGSIZE in this case
(see error table here).
This is an unfortunate inconsistency. The following test case fails on Windows
but succeeds everywhere else:
The trivial fix would be to add a check for WSAEMSGSIZE in the Windows implementation of recvfrom
and returning n == len(buf) and a nil error instead. Another fix could be to mark the error as temporary.
Is this something we want to fix? The UDPConn documentation does not dictate any particular behavior for oversized datagrams, so what happens on Windows is technically valid. Yet working around this issue
is very inconvenient and requires unpacking/comparing of errno and use of package syscall.
The text was updated successfully, but these errors were encountered: