You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[wasi-sockets] Inconsistency with inherited properties #12561
I looked at the SO_RCVBUF & SO_SNDBUF implementations of Linux & MacOS.
By default, both platforms use a dynamic buffer capacity feature, which is disabled when the user explicitly sets SO_RCVBUF or SO_SNDBUF. On Linux the relevant search terms are SOCK_SNDBUF_LOCK & SOCK_RCVBUF_LOCK. On MacOS this is controlled by SB_AUTOSIZE.
That explains the behavior observed in this issue.
Also relevant:
On MacOS, the socket options reflect the current capacity of the buffer. If not explicitly set, getsockopt may return different values over the lifetime of the connection as the buffer fills & drains.
On Linux, the socket options reflect the maximum buffer capacity. If not explicitly set, Linux computes a maximum based on connection statistics. This currently occurs only once when the connection is established. This causes the one-time jump in the value returned by getsockopt, which afterwards remains stable.
Importantly, this behavior is not specific to listener sockets or inheritance. The same effect occurs on client sockets. Example:
With this in mind, the underlying issue seems less about inheritance and more about the fact that getsockopt(SO_RCVBUF or SO_SNDBUF) returns meaningless values until either:
the option has been explicitly set, or
a connection has been established.
It's unclear to me how WASI should handle this situation. Automatically calling setsockopt on every accepted socket just to satisfy a single test seems undesirable, as it would add runtime overhead and disable the kernel's dynamic buffer sizing.
One option is to leave the behavior as-is and simply document these platform-specific quirks.
Another possibility is to have get_send/receive_buffer_size return an error until the buffer size has been explicitly set or the socket has been connected. From my current understanding, there is rarely a meaningful use case for reading these values beforehand anyways. But I can't predict how many existing applications might break because of that.
Edit: instead of returning an error, maybe returning 0 may not be so bad. Which can be interpreted as: the socket starts out with an empty buffer.
In summary, I understand the problem now but I don't know the best way forward yet.
@saulecabrera Given the findings above, I think the conclusion here is that the test code is incorrect to assume an exact match on the value of get_{receive,send}_buffer_size obtained from before the connection was established. The WASI spec has been updated to include:
/// This is only a performance hint. The implementation may ignore it or
/// tweak it based on real traffic patterns.
/// Linux and macOS appear to behave differently depending on whether a
/// buffer size was explicitly set. When set, they tend to honor it; when
/// not set, they dynamically adjust the buffer size as the connection
/// progresses. This is especially noticeable when comparing the values
/// from before and after connection establishment.
I think the best way forward here is to remove the buffer size assertions from your test.
Activity
saulecabrera commentedon Feb 10, 2026
The inconsistency only seems to be happening when the values are not explicitly set by calling the respective setters i.e., if explicitly set, it works as expected, according to this test https://github.com/bytecodealliance/wasmtime/blob/main/crates/test-programs/src/bin/p3_sockets_tcp_sockopts.rs#L113
alexcrichton commentedon Feb 10, 2026
cc @badeend
badeend commentedon Feb 11, 2026
Heh, nice find ;)
Let me find out why this is happening
badeend commentedon Feb 15, 2026
I looked at the
SO_RCVBUF&SO_SNDBUFimplementations of Linux & MacOS.By default, both platforms use a dynamic buffer capacity feature, which is disabled when the user explicitly sets
SO_RCVBUForSO_SNDBUF. On Linux the relevant search terms areSOCK_SNDBUF_LOCK&SOCK_RCVBUF_LOCK. On MacOS this is controlled bySB_AUTOSIZE.That explains the behavior observed in this issue.
Also relevant:
getsockoptmay return different values over the lifetime of the connection as the buffer fills & drains.Importantly, this behavior is not specific to listener sockets or inheritance. The same effect occurs on client sockets. Example:
Prints:
With this in mind, the underlying issue seems less about inheritance and more about the fact that
getsockopt(SO_RCVBUF or SO_SNDBUF)returns meaningless values until either:It's unclear to me how WASI should handle this situation. Automatically calling
setsockopton every accepted socket just to satisfy a single test seems undesirable, as it would add runtime overhead and disable the kernel's dynamic buffer sizing.get_send/receive_buffer_sizereturn an error until the buffer size has been explicitly set or the socket has been connected. From my current understanding, there is rarely a meaningful use case for reading these values beforehand anyways. But I can't predict how many existing applications might break because of that.In summary, I understand the problem now but I don't know the best way forward yet.
Update sockets documentation:
sockets: Update documentation (#884)
badeend commentedon Mar 14, 2026
@saulecabrera Given the findings above, I think the conclusion here is that the test code is incorrect to assume an exact match on the value of
get_{receive,send}_buffer_sizeobtained from before the connection was established. The WASI spec has been updated to include:I think the best way forward here is to remove the buffer size assertions from your test.
alexcrichton commentedon Mar 16, 2026
Thanks @badeend! I'll consider this closed by WebAssembly/WASI#884
Remove buffer size assertions