UDP: set max buffer size to 4MB and fallback to 1MB#6989
UDP: set max buffer size to 4MB and fallback to 1MB#6989elgiano merged 4 commits intosupercollider:3.14from
Conversation
We fallback to 1MB if we fail to do that.
telephon
left a comment
There was a problem hiding this comment.
Thank you!
I think it would be good if sclang would inform us always about the current maximum OSC buffer size, and even keep a variable for this that can be accessed from within sclang.
There are places in the class library where we depend on the size limit, so these need to adjust themselves.
This could be a separate PR, of course.
|
@telephon I found these four matches searching for 65535, do you think there are more? supercollider/SCClassLibrary/Common/Audio/SynthDef.sc Lines 598 to 605 in e8a06ee supercollider/SCClassLibrary/Common/Control/NetAddr.sc Lines 101 to 102 in e8a06ee supercollider/SCClassLibrary/Common/Control/NetAddr.sc Lines 121 to 122 in e8a06ee supercollider/SCClassLibrary/JITLib/ProxySpace/ProxyInterfaces.sc Lines 363 to 370 in e8a06ee About being able to query the maxBufferSize (and perhaps even setting it?) I agree it would be nice to have a couple of primitives (something like _NetAddr_getMaxBufferSize, _NetAddr_setMaxBufferSize), especially because now different systems could have different buffer sizes and being able to query it would help debugging eventual future issues. |
| static constexpr int receiveBufferSize = 8 * 1024 * 1024; | ||
| static constexpr int sendBufferSize = 8 * 1024 * 1024; | ||
| static constexpr int receiveBufferSize = 4 * 1024 * 1024; | ||
| static constexpr int sendBufferSize = 4 * 1024 * 1024; |
There was a problem hiding this comment.
I think we should add static constexpr int fallbackBufferSize = 1 * 1024 * 1024, and perhaps move all these constexpr to common/SC_OscUtils.hpp?
There was a problem hiding this comment.
Actually, we could make a function setUDPBufferSizes in there, and call it from sclang/scsynth/supernova. But we could also do this in a subsequent refactoring PR
There was a problem hiding this comment.
I think we should add static constexpr int fallbackBufferSize = 1 * 1024 * 1024
Most definitely.
There was a problem hiding this comment.
Actually, we could make a function setUDPBufferSizes in there, and call it from sclang/scsynth/supernova.
I'm thinking about this, too. If that is what we want, I plan to move them all to SC_OscUtils.hpp.
There was a problem hiding this comment.
I've seen that if we want to do this, there is a caveat to import SC_OscUtils.hpp in supernova
#define scprintf printf
#include "SC_OscUtils.hpp"
#undef scprintfwhich is the same thing we do in lang/LangPrimSource/SC_ComPort.cpp.
But again, I don't think it's absolutely necessary to do it now, we could also do it after release in a subsequent PR, as you wish
As @elgiano correctly pointed out, these size checks are only done to make sure we don't exceed the max. UDP packet size. The UDP socket buffers should always be large enough to hold at least a single UDP packet. |
Yes, that's what I think as well. It seems pretty arbitrary to me, though. Note that 65535 is only the max. value allowed in the size field of the UDP packet header (because it is a 16-bit unsigned integer.) For the actual max. data payload, you must subtract the UDP header size (8 bytes) and IP header size (20 bytes for IPv4). For IPv4 this is 65507 bytes. See https://en.wikipedia.org/wiki/User_Datagram_Protocol#UDP_datagram_structure. But that does not mean that you can actually send and receive such large UDP packets, in particular when an actual network is involved (as opposed to loopback devices). The ethernet standard only guarantees an MTU of 1500 bytes. Most modern switches support jumbo frames (https://en.wikipedia.org/wiki/Jumbo_frame), but they also have a limit well below 65507. Once you send things over the internet, you might want to limit your UDP packets to something like 576 (!) bytes. IMO, the actual solution to all of this is to use a reliable protocol, like TCP, but that's another story. |
No, methink that's it. Thank you for the explanation, sure! |
iirc, i did experiments and found that value :D. Might be wrong by now! |
elgiano
left a comment
There was a problem hiding this comment.
Looks good to me, thanks! We can follow up later with a refactoring to reduce code duplication!
|
@JordanHendersonMusic / @Spacechild1 is this good to be merged? |
|
Good from my side! |
|
Does this fix #6969? |
|
Probably, but it would be nice if @ahihi could test it once we release rc2, since none of us could reproduce the error
-------- Original Message --------
On 6/21/25 18:50, Jordan Henderson wrote:
JordanHendersonMusic left a comment [(supercollider/supercollider#6989)](#6989 (comment))
Does this fix [#6969](#6969)?
—
Reply to this email directly, [view it on GitHub](#6989 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AACNMWVTCQHEWDNEFGYFYB33EWEMHAVCNFSM6AAAAAB7LKDDI2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSOJTGY3DSOJRGI).
You are receiving this because you modified the open/close state.Message ID: ***@***.***>
@github.com>
|
i will! in fact i would be happy to try it already, but i dont currently have a SC build environment set up. |
|
@ahihi you can find builds from Github Actions under "Checks":
On macOS you need to right-click -> open (two times) to be able to run an unsigned build. |
thanks! it is working fine here :) |
Failing to set the previous 8MB buffer size could leave some systems with a too small default, causing failures when sending bigger synthdefs, with _NetAddr_SendMsg error "Message too long". 4MB is still more than the default in 3.13, while being acceptable for most systems. If it's still too much, fallback to 1MB if system's default is smaller.

Purpose and Motivation
Fix #6969. Set UDP buffer size to 4 MB and fallback to 1MB if we fail to do that.
Types of changes
To-do list