Stream: git-wasmtime

Topic: wasmtime / PR #14518 reset P2 TCP sockets closed with unr...


view this post on Zulip Wasmtime GitHub notifications bot (Oct 03 2026 at 20:52):

macovedj opened PR #14518 from macovedj:p2-tcp-close-unread-rst to bytecodealliance:main:

Closing a P2 TCP socket with unread received data currently shuts down its retained streams before closing the native descriptor. The peer can therefore observe a clean EOF instead of the connection reset expected when closing a socket with unread data.

This PR resets connected sockets with unread data before their retained streams drop, using zero linger plus connect(AF_UNSPEC) on Linux/Android and disconnectx on Apple targets.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 03 2026 at 20:52):

macovedj requested alexcrichton for a review on PR #14518.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 03 2026 at 20:52):

macovedj requested wasmtime-wasi-reviewers for a review on PR #14518.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 03 2026 at 20:52):

macovedj requested wasmtime-default-reviewers for a review on PR #14518.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 04 2026 at 01:48):

github-actions[bot] added the label wasi on PR #14518.

view this post on Zulip Wasmtime GitHub notifications bot (Oct 05 2026 at 21:29):

pchickey commented on PR #14518:

Like #14461 I would need @badeend to take a look at this

view this post on Zulip Wasmtime GitHub notifications bot (Nov 14 2026 at 11:58):

badeend commented on PR #14518:

Hi! Could you maybe elaborate a bit on what problem this solves? Is there an application that relies on the peer seeing a reset? At first sight, I wouldn't expect the RST guarantee to offer much value in practice: any guest that buffers reads in memory (which is e.g. Node.js’s default), would already have drained the kernel buffer, so closing it sends a FIN anyway.

A more practical concern is that WASI 0.3 has no explicit close for sockets. The OS socket closes automatically once the last resource derived from it is dropped. So if this turns out to be a real problem, P3 has it too, and P3 can’t be fixed under the current spec. Changing only P2 makes it behave in a way 0.3 can’t express. If we decide this RST is worth guaranteeing to guests, I think the 0.3 spec should be updated to support it first, so that 0.2 stays implementable on top of 0.3 and won't need special host magic.

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

macovedj commented on PR #14518:

Thanks for taking a look. I’m working on a Node-compatible runtime targeting Wasm, which is how I encountered this. The motivation is the observable difference between native close and Wasmtime’s P2 close, which can be observed in this small reproducer I created. TCP RFC 9293 §3.6.1 says that when a host uses a half-duplex close with received data still pending, TCP SHOULD send RST to signal that data was lost.

You’re right that if a guest has already read the bytes into its own buffer, they won’t remain in the kernel receive queue to trigger this reset. In the motivating case, though, the extra bytes arrive after the read that delivered the request, while a synchronous handler is running. The response and close run in process.nextTick(), before another I/O turn, and the trace shows no further socket read. In that run, the bytes remain in the OS receive queue: native close yields RST, while the P2 path shuts down the retained streams first and yields EOF. Native Node’s read buffering therefore doesn’t explain this difference. Node’s own test notes that a reset after destroy() depends on OS and timing.

I hadn't considered that this may be more difficult to handle for 0.3. If this behavior seems worth specifying, I’d be happy to bring the reproducer to a WASI sockets issue so we can work out the 0.3 contract before deciding on the P2 change.


Last updated: Nov 19 2026 at 20:05 UTC