Skip to content

Commit 2bcfe5b

Browse files
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
1 parent 2183283 commit 2bcfe5b

6 files changed

+23
-5
lines changed

send_queue.go

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

sys_conn_df.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ func setDF(syscall.RawConn) (bool, error) {
1111
return false, nil
1212
}
1313

14-
func isMsgSizeErr(err error) bool {
14+
func isSendMsgSizeErr(err error) bool {
15+
// to be implemented for more specific platforms
16+
return false
17+
}
18+
19+
func isRecvMsgSizeErr(err error) bool {
1520
// to be implemented for more specific platforms
1621
return false
1722
}

sys_conn_df_darwin.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ func setDF(rawConn syscall.RawConn) (bool, error) {
4747
return true, nil
4848
}
4949

50-
func isMsgSizeErr(err error) bool {
50+
func isSendMsgSizeErr(err error) bool {
5151
return errors.Is(err, unix.EMSGSIZE)
5252
}
5353

54+
func isRecvMsgSizeErr(error) bool { return false }
55+
5456
func isAtLeastMacOS11() (bool, error) {
5557
uname := &unix.Utsname{}
5658
err := unix.Uname(uname)

sys_conn_df_linux.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ func maybeSetGSO(rawConn syscall.RawConn) bool {
5757
return true
5858
}
5959

60-
func isMsgSizeErr(err error) bool {
60+
func isSendMsgSizeErr(err error) bool {
6161
// https://man7.org/linux/man-pages/man7/udp.7.html
6262
return errors.Is(err, unix.EMSGSIZE)
6363
}
6464

65+
func isRecvMsgSizeErr(err error) bool { return false }
66+
6567
func appendUDPSegmentSizeMsg(b []byte, size uint16) []byte {
6668
startLen := len(b)
6769
const dataLen = 2 // payload is a uint16

sys_conn_df_windows.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ func setDF(rawConn syscall.RawConn) (bool, error) {
4343
return true, nil
4444
}
4545

46-
func isMsgSizeErr(err error) bool {
46+
func isSendMsgSizeErr(err error) bool {
47+
// https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
48+
return errors.Is(err, windows.WSAEMSGSIZE)
49+
}
50+
51+
func isRecvMsgSizeErr(err error) bool {
4752
// https://docs.microsoft.com/en-us/windows/win32/winsock/windows-sockets-error-codes-2
4853
return errors.Is(err, windows.WSAEMSGSIZE)
4954
}

transport.go

+4
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,10 @@ func (t *Transport) listen(conn rawConn) {
330330
continue
331331
}
332332
if err != nil {
333+
// Windows returns an error when receiving a UDP datagram that doesn't fit into the provided buffer.
334+
if isRecvMsgSizeErr(err) {
335+
continue
336+
}
333337
t.close(err)
334338
return
335339
}

0 commit comments

Comments
 (0)