Skip to content

Cap Number of Open TCP and UDP Sockets#3537

Open
rylev wants to merge 3 commits into
mainfrom
socket-cap
Open

Cap Number of Open TCP and UDP Sockets#3537
rylev wants to merge 3 commits into
mainfrom
socket-cap

Conversation

@rylev
Copy link
Copy Markdown
Collaborator

@rylev rylev commented May 27, 2026

This adds the ability to limit the number of open TCP and UDP sockets to a set number so that embedders can more easily control the number of open file descriptors they have.

rylev added 2 commits May 26, 2026 18:03
Signed-off-by: Ryan Levick <rlevick@akamai.com>
Signed-off-by: Ryan Levick <rlevick@akamai.com>
@rylev rylev requested a review from lann May 27, 2026 12:03
Comment thread crates/factor-wasi/src/lib.rs Outdated
Comment thread crates/factor-wasi/src/lib.rs Outdated
Comment on lines +113 to +116
let Ok(permit) = Arc::clone(&state.semaphore).try_acquire_owned() else {
// wasi has no "quota exceeded" error code. ConnectionRefused is the closest available.
return Err(SocketErrorCode::ConnectionRefused.into());
};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The outbound http version of this waits for a permit. I don't have a strong opinion at the moment about whether that is better or worse than failing but it seems like we should be consistent.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Separately, it we do end up returning an error here we should probably at least emit a tracing event.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure that it does make sense to have the same semantics for outbound HTTP and raw sockets. Outbound HTTP slots are freed by the runtime when the response comes back. There's no explicit guest action required to free the resource and open the slot. This means in the fullness of time slots are guaranteed to eventually become available. Socket slots, by contrast, are only freed when the guest explicitly drops the resource. This means a guest holding N sockets and waiting for an N+1th permit will deadlock. It can never release the permits it holds while suspended waiting for a new one.

Signed-off-by: Ryan Levick <rlevick@akamai.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants