Cap Number of Open TCP and UDP Sockets#3537
Conversation
Signed-off-by: Ryan Levick <rlevick@akamai.com>
Signed-off-by: Ryan Levick <rlevick@akamai.com>
| 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()); | ||
| }; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Separately, it we do end up returning an error here we should probably at least emit a tracing event.
There was a problem hiding this comment.
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.
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.