check for WSAEMSGSIZE errors when receiving UDP packets on Windows (#3982)

* check for WSAEMSGSIZE errors when receiving UDP packets on Windows

* check EMSGSIZE error on macOS
This commit is contained in:
Marten Seemann 2023-07-20 20:31:57 -07:00 committed by GitHub
parent 2183283622
commit 2bcfe5bc4b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 5 deletions

View file

@ -82,7 +82,7 @@ func (h *sendQueue) Run() error {
// 1. Checking for "datagram too large" message from the kernel, as such,
// 2. Path MTU discovery,and
// 3. Eventual detection of loss PingFrame.
if !isMsgSizeErr(err) {
if !isSendMsgSizeErr(err) {
return err
}
}

View file

@ -11,7 +11,12 @@ func setDF(syscall.RawConn) (bool, error) {
return false, nil
}
func isMsgSizeErr(err error) bool {
func isSendMsgSizeErr(err error) bool {
// to be implemented for more specific platforms
return false
}
func isRecvMsgSizeErr(err error) bool {
// to be implemented for more specific platforms
return false
}

View file

@ -47,10 +47,12 @@ func setDF(rawConn syscall.RawConn) (bool, error) {
return true, nil
}
func isMsgSizeErr(err error) bool {
func isSendMsgSizeErr(err error) bool {
return errors.Is(err, unix.EMSGSIZE)
}
func isRecvMsgSizeErr(error) bool { return false }
func isAtLeastMacOS11() (bool, error) {
uname := &unix.Utsname{}
err := unix.Uname(uname)

View file

@ -57,11 +57,13 @@ func maybeSetGSO(rawConn syscall.RawConn) bool {
return true
}
func isMsgSizeErr(err error) bool {
func isSendMsgSizeErr(err error) bool {
// https://man7.org/linux/man-pages/man7/udp.7.html
return errors.Is(err, unix.EMSGSIZE)
}
func isRecvMsgSizeErr(err error) bool { return false }
func appendUDPSegmentSizeMsg(b []byte, size uint16) []byte {
startLen := len(b)
const dataLen = 2 // payload is a uint16

View file

@ -43,7 +43,12 @@ func setDF(rawConn syscall.RawConn) (bool, error) {
return true, nil
}
func isMsgSizeErr(err error) bool {
func isSendMsgSizeErr(err error) bool {
// https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
return errors.Is(err, windows.WSAEMSGSIZE)
}
func isRecvMsgSizeErr(err error) bool {
// https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
return errors.Is(err, windows.WSAEMSGSIZE)
}

View file

@ -330,6 +330,10 @@ func (t *Transport) listen(conn rawConn) {
continue
}
if err != nil {
// Windows returns an error when receiving a UDP datagram that doesn't fit into the provided buffer.
if isRecvMsgSizeErr(err) {
continue
}
t.close(err)
return
}