Fix sockets not getting an ephemeral port between bind() and listen()#6473
Closed
Arshia001 wants to merge 7 commits intowasmerio:mainfrom
Closed
Fix sockets not getting an ephemeral port between bind() and listen()#6473Arshia001 wants to merge 7 commits intowasmerio:mainfrom
Arshia001 wants to merge 7 commits intowasmerio:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses wasix TCP semantics so bind(..., port=0) allocates an ephemeral port immediately (before listen()/connect()), matching POSIX behavior and fixing #6403. It does so by introducing an explicit “bound TCP” state in virtual-net and plumbing it through wasix, journaling, and tests.
Changes:
- Add WASIX wasm regression tests for
bind(port=0)behavior (port becomes nonzero afterbind(); remains stable afterlisten()/connect()). - Extend
virtual-netwithbind_tcp+VirtualTcpBoundSocket, implement it for host/loopback/remote backends, and add unit tests. - Update wasix socket state machine + journaling to capture the effective bound address (including ephemeral port).
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lib/wasix/tests/wasm_tests/socket_tests/bind-port-zero/main.c | New wasm test asserting ephemeral port allocation happens at bind() and is stable across listen(). |
| lib/wasix/tests/wasm_tests/socket_tests/bind-port-zero/build.sh | Build script for the new wasm test. |
| lib/wasix/tests/wasm_tests/socket_tests/bind-port-zero-connect/main.c | New wasm test asserting bind-assigned ephemeral port stays stable across connect(). |
| lib/wasix/tests/wasm_tests/socket_tests/bind-port-zero-connect/build.sh | Build script for the new wasm test. |
| lib/wasix/tests/wasm_tests/socket_tests.rs | Registers the two new wasm socket tests in the Rust harness. |
| lib/wasix/src/syscalls/wasix/sock_bind.rs | Journals the effective local address after bind (important for port=0 correctness in replay). |
| lib/wasix/src/net/socket.rs | Introduces BoundTcp inode socket state; updates bind/listen/connect/addr_local/status paths accordingly. |
| lib/virtual-net/src/lib.rs | Adds VirtualNetworking::bind_tcp and the VirtualTcpBoundSocket trait. |
| lib/virtual-net/src/host.rs | Implements bind_tcp using socket2 and adds LocalTcpBoundSocket. |
| lib/virtual-net/src/loopback.rs | Implements bind_tcp for loopback and allocates ephemeral ports at bind time. |
| lib/virtual-net/src/meta.rs | Extends remote protocol with BindTcp, ListenBound, and ConnectBound. |
| lib/virtual-net/src/client.rs | Implements remote bind_tcp and bound-socket transitions; adds binding-ownership tracking. |
| lib/virtual-net/src/server.rs | Implements server-side handling for BindTcp and bound-socket transitions. |
| lib/virtual-net/src/tests.rs | Adds tests covering ephemeral port allocation at bind and stability across listen/connect. |
| docs/dev/issue-6403-tcp-bind-plan.md | Adds an implementation plan / rationale document for #6403. |
Comments suppressed due to low confidence (1)
lib/virtual-net/src/client.rs:930
RemoteNetworkingClient::new_socket()inserts per-socket entries intoaccept_txandsent_tx, butDrop for RemoteSocketonly removesrecv_txandrecv_with_addr_tx. This will grow the maps over time (socket IDs are monotonically increasing) and can leak memory/resources. Remove the correspondingaccept_txandsent_txentries on drop as well (guarded byowns_socket_bindings, like the others).
self.common.recv_tx.lock().unwrap().remove(&self.socket_id);
self.common
.recv_with_addr_tx
.lock()
.unwrap()
.remove(&self.socket_id);
Contributor
|
/patchsmith test |
Member
Author
|
too early @artem, let's wait for CI to turn green first |
Contributor
|
Cool, but can you resubmit it as PR on branch in this repo? patchsmith unfortunately doesn't run on the forks yet |
Member
Author
|
will do once all patches are in @artemyarulin |
Member
Author
|
Superseded by #6478 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.