Our system occasionally sees this error returned by *net.UDPConn.Read(byte[])
:
read udp [::]:7089: wsarecv: A message sent on a datagram socket was
larger than the internal message buffer or some other network limit,
or the buffer used to receive a datagram into was smaller than the
datagram itself.
(The read buffer is bigger than the MTU)
As this is probably a data error rather than a network error, I would like to test for this error so that I handle it appropriately.
What value can I give to errors.Is
to identify these errors?
*update – running on Windows, this appears to correspond to winsock WSAEMSGSIZE message, how do I code that into Go?
6
You can import golang.org/x/sys/windows and then do:
import (
"errors"
"net"
"golang.org/x/sys/windows"
)
func ...(conn net.Conn) {
// ...
_, err := conn.Read(...)
if errors.Is(err, windows.WSAEMSGSIZE) {
// ...
}
}