-
Notifications
You must be signed in to change notification settings - Fork 18.1k
net: UDPConn.SetReadBuffer unexpected behavior on BSD architectures #13193
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
Comments
Can you test what happens with the equivalent C code? The Go code really is just calling setsockopt(SO_RCVBUF, bytes); I don't know why Go would behave differently than C here. |
I can test but I'm not very good with C, could you provide any guidance on how I might call the C function directly? |
Try this. READBUFFER is the size of the read buffer being requested. By the way, in your Go example, you should check the error return of ResolveUDPAddr: ":80891" is not a valid UDP address.
|
Okay, @fenderle helped me figure this out, it looks like BSD makes some sort of adjustment to the actual limit here: https://github.com/freebsd/freebsd/blob/master/sys/kern/uipc_sockbuf.c#L385-L399 which gets triggered from here: https://github.com/freebsd/freebsd/blob/master/sys/kern/uipc_sockbuf.c#L420 so the actual buffer limit is not 8388608, it's actually
(where 8388608 == So I think we can close this issue....I don't think it's within Go's domain to adjust for this, BSD is weird. |
When using UDPConn.SetReadBuffer, I expect to be able to set the buffer up to the kernel limit
kern.ipc.maxsockbuf
, but I am getting failures on Darwin and FreeBSD when trying to do that.From what I can tell, this should be supported, assuming the code is doing a
setsockopt
on theSO_RCVBUF
constant, from the bsd setsockopt man page:Versions
and FreeBSD:
What did you do?
This script fails on any BSD/Darwin architecture, where
ReadBuffer
is set equal tokern.ipc.maxsockbuf
, error output I get isset udp [::]:55647: setsockopt: no buffer space available
What did you expect to see?
I would expect
conn.SetReadBuffer(ReadBuffer)
to succeed whenReadBuffer
is less than or equal tokern.ipc.maxsockbuf
What did you see instead?
On BSD/Darwin,
conn.SetReadBuffer(ReadBuffer)
fails whenReadBuffer
is equal tokern.ipc.maxsockbuf
. From my limited testing it doesn't start passing until you subtract ~12% from the max.The text was updated successfully, but these errors were encountered: