Stream: git-wasmtime

Topic: wasmtime / issue #12561 [wasi-sockets] Inconsistency with...


view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 20:21):

saulecabrera opened issue #12561:

In the following snippet:

    let mut accept = sock.listen().unwrap();
    futures::join!(
        async {
            let next = accept.next().await.unwrap();
            assert_eq!(next.get_address_family(), sock.get_address_family());
            assert_eq!(next.get_keep_alive_enabled(), sock.get_keep_alive_enabled());
            assert_eq!(
                next.get_keep_alive_idle_time(),
                sock.get_keep_alive_idle_time()
            );
            assert_eq!(
                next.get_keep_alive_interval(),
                sock.get_keep_alive_interval()
            );
            assert_eq!(next.get_keep_alive_count(), sock.get_keep_alive_count());
            assert_eq!(next.get_hop_limit(), sock.get_hop_limit());

            // The following asserts fail.
            assert_eq!(
                next.get_receive_buffer_size(),
                sock.get_receive_buffer_size()
            );
            assert_eq!(next.get_send_buffer_size(), sock.get_send_buffer_size());
        },
        async {
            client.connect(local_addr).await.unwrap();
        }
    );

The values for get_receive_buffer_size() and get_send_buffer_size() are different between the listener and the handler socket.

According to the spec:

The following properties are inherited from the listener socket:

Platform specific information:

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 20:21):

saulecabrera added the bug label to Issue #12561.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 20:21):

saulecabrera added the wasi label to Issue #12561.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 20:43):

saulecabrera commented on issue #12561:

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

view this post on Zulip Wasmtime GitHub notifications bot (Feb 10 2026 at 22:30):

alexcrichton commented on issue #12561:

cc @badeend

view this post on Zulip Wasmtime GitHub notifications bot (Feb 11 2026 at 19:57):

badeend commented on issue #12561:

Heh, nice find ;)

Let me find out why this is happening

view this post on Zulip Wasmtime GitHub notifications bot (Feb 15 2026 at 13:25):

badeend commented on issue #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:

Importantly, this behavior is not specific to listener sockets or inheritance. The same effect occurs on client sockets. Example:

let recv_before = sock.get_receive_buffer_size().unwrap();
let send_before = sock.get_send_buffer_size().unwrap();

sock.connect(addr).await.unwrap();

let recv_after = sock.get_receive_buffer_size().unwrap();
let send_after = sock.get_send_buffer_size().unwrap();

println!("Recv {recv_before} -> {recv_after}");
println!("Send {send_before} -> {send_after}");

Prints:

Recv 65536 -> 65536
Send 8192 -> 43520

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 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.

In summary, I understand the problem now but I don't know the best way forward yet.

view this post on Zulip Wasmtime GitHub notifications bot (Feb 15 2026 at 14:16):

badeend edited a comment on issue #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:

Importantly, this behavior is not specific to listener sockets or inheritance. The same effect occurs on client sockets. Example:

let recv_before = sock.get_receive_buffer_size().unwrap();
let send_before = sock.get_send_buffer_size().unwrap();

sock.connect(addr).await.unwrap();

let recv_after = sock.get_receive_buffer_size().unwrap();
let send_after = sock.get_send_buffer_size().unwrap();

println!("Recv {recv_before} -> {recv_after}");
println!("Send {send_before} -> {send_after}");

Prints:

Recv 65536 -> 65536
Send 8192 -> 43520

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 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.

In summary, I understand the problem now but I don't know the best way forward yet.


Last updated: Feb 24 2026 at 04:36 UTC