Each connection runs on its own OS thread with its own V8 isolates, so connection count is what drives the server's thread footprint. MAX_PENDING_WS_HANDOFFS bounds only the handoff queue: once a stream is handed off, nothing limited how many could be live at once, and a client could grow the server without limit. Reserve a slot in the accept loop and release it from a guard that runs when the connection thread unwinds, on every path including panics and the early returns before the runtime is built -- a plain decrement at the end of the closure would leak slots until the cap wedged the server shut. Connections past the limit get an explicit 503 with X-Obscura-Reason: max-connections rather than a bare reset, so a client can tell a refusal from a crash. The refusal happens in the WS dispatch loop, so the HTTP control plane (#62) stays reachable at the cap. Default 128, matching the handoff bound and well above any real client fan-out (Playwright/Puppeteer use one connection per browser). At the cap, with arenas capped by the previous commit: 146 threads, 33.2 GiB of reserved address space and 51 MiB resident -- nearly all of that reservation being V8's process-wide sandbox, which is present at zero connections. Threads are the honest cost here, not memory: at 100 connections each running JS this server reserves 83.5 GiB against `main`'s 83.6 GiB, because `main` pays the same V8 sandbox as soon as it runs any JS. What it does not pay is 118 threads against 17. The test covers all three properties, and specifically that a closed connection frees its slot: a leak there would only surface as a server that silently stops accepting after N lifetime connections. Refs #430.
13 lines
335 B
Rust
13 lines
335 B
Rust
pub mod server;
|
|
pub mod dispatch;
|
|
pub mod types;
|
|
pub mod domains;
|
|
pub mod cookie_params;
|
|
pub(crate) mod util;
|
|
|
|
pub use server::{
|
|
start, start_with_full_options, start_with_full_serve_options, start_with_host,
|
|
start_with_host_and_security, start_with_options, start_with_serve_options_and_limit,
|
|
DEFAULT_MAX_CONNECTIONS,
|
|
};
|