Skip to content

Conversation

@badeend
Copy link
Member

@badeend badeend commented Dec 28, 2025

In 0.2, implicit binds were explicitly forbidden, because that would bypass the concept of network handles.
0.3 doesn't have network handles and sockets are allowed to perform implicit binds again. This affects:

  • tcp-socket::listen (documented here)
  • udp-socket::connect (documented here)
  • udp-socket::send

Eventually, this will also allow us to remove the double bookkeeping like this from wasi-libc.

@badeend badeend requested review from a team as code owners December 28, 2025 21:48
@badeend badeend requested review from dicej and removed request for a team December 28, 2025 21:48
@github-actions github-actions bot added the wasi Issues pertaining to WASI label Dec 28, 2025
Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the comprehensive tests and the implementation here, much appreciated!

@alexcrichton alexcrichton added this pull request to the merge queue Jan 5, 2026
github-merge-queue bot pushed a commit that referenced this pull request Jan 5, 2026
* Allow TCP `listen` to be called without an explicit `bind` on P3.

* Allow UDP `connect` to be called without an explicit `bind` on P3.

* Add test to verify that `receive` requires the socket to be bound.

* Allow UDP `send` to be called on an unbound socket on P3.

* Add feature flags

* Add docs

* Resolve "unused imports" warning
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 5, 2026
@badeend
Copy link
Member Author

badeend commented Jan 5, 2026

Interesting. I was under the impression that implicit bind was a well-known universal behavior, but after some more research it appears to be a bit more nuanced than I thought. I've added a comment in the code with my findings.

But practically, Linux & MacOS both successfully ran to completion with:

test p3::p3_sockets_tcp_listen ... ok

So they perform an implicit bind as expected (but not clearly documented). I assume this behavior extrapolates to other *BSD flavors.

But apparently, Windows requires bind to be called before listen. To take away any potential platform-specific differences, I've updated the code to always perform the "implicit" bind ourselves in case the socket wasn't explicitly bound by the guest.

Assuming this actually fixes the CI problems, I'll open a PR for a spec change to add a clarification on the listen method.

@alexcrichton Could you review the changes I just added?

@alexcrichton
Copy link
Member

Sounds right to me yeah, and thanks for investigating!

@alexcrichton alexcrichton added this pull request to the merge queue Jan 5, 2026
Merged via the queue into bytecodealliance:main with commit 2cd7e17 Jan 5, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants