Bind and size the workers
WireframeServer is a typestate. from_app takes a built application and new takes a factory, and both return an unbound server; bind or bind_existing_listener returns a bound one, which can report local_addr and run. Configuration that belongs before binding, such as workers, backoff, readiness, and the preamble, is set on either.
let backoff = BackoffConfig {
initial_delay: Duration::from_millis(10),
max_delay: Duration::from_secs(1),
};
let server = WireframeServer::new(app)
.workers(4)
.accept_backoff(backoff)
.bind("127.0.0.1:0".parse().expect("a socket address"))
.expect("bind");
assert_eq!(server.worker_count(), 4);
let (stop, stopped) = oneshot::channel::<()>();
let running = tokio::spawn(server.run_with_shutdown(async {
let _ = stopped.await;
}));
stop.send(()).expect("the server is listening for shutdown");
running
.await
.expect("the server task joins")
.expect("a clean stop");
- Workers. One accept-loop task per worker, defaulting to the available parallelism, which respects CPU quotas, and never fewer than one.
- Applications. The factory runs once per server run, and the application is prepared before the server reports readiness. Every worker and connection shares that one immutable application, so per-connection state belongs in
on_connection_setup. - Accept backoff. When
acceptfails, as it does when the process runs out of file descriptors, a worker waits and retries with exponential backoff betweeninitial_delayandmax_delay. Out-of-range values are corrected, not rejected. - Panics. A panic inside a connection task is caught, logged, and counted; the worker and every other connection carry on.
A factory may return a Result. Its failure, or a failure to prepare the application, comes back from the run as a ServerError rather than a half-started server:
fn fallible_app() -> Result<WireframeApp, io::Error> {
Err(io::Error::other("no configuration"))
}
let server = WireframeServer::new(fallible_app)
.bind("127.0.0.1:0".parse().expect("a socket address"))
.expect("bind");
let refused = server.spawn().await;
assert!(matches!(refused, Err(ServerError::FactoryBuild(_))));
Readiness and shutdown
ready_signal takes a oneshot sender that fires once the workers are accepting, which is what a test or an orchestration probe should wait for. There are three ways to run and stop a server: run serves until Ctrl+C; run_with_shutdown serves until the future it is given completes, and dropping the future run_with_shutdown returns cancels the accept loops, so keep it alive for as long as the server should run; and spawn runs in the background and returns a cloneable ServerShutdown, whose stop requests shutdown and whose drained waits for it to finish. Dropping the last clone also requests shutdown.
shutdown.stop();
tokio::time::timeout(Duration::from_secs(5), shutdown.drained())
.await
.expect("a handler that never returns would hold up the drain")
.expect("a clean stop");
Timeouts and failure limits
| Setting | Default | Effect in 0.4.0-alpha1 |
|---|---|---|
buffer_capacity | 1,024 bytes | Frames over the limit are a decoder error, and the connection closes |
read_timeout_ms | 100 ms | A housekeeping interval: when it elapses with no frame, expired partial messages are purged and the connection keeps waiting |
| Deserialization failures | 10 | The connection closes; a fully dispatched message resets the count |
preamble_timeout | 10 seconds | Bounds the preamble read when with_preamble sets one; on expiry the failure handler runs and the connection closes. Without a preamble nothing is read, so it never fires. disable_preamble_timeout removes it, and with it the protection against peers that connect and say nothing |
| Decode limit | 16 MiB | Bounds peer-declared container lengths in the bundled decoders; fixed |
| Memory budgets | 16, 64, 64 × frame limit | Reads slow at 80% of the aggregate cap and the connection closes past it; see memory budgets |
| Fragmentation | Off | See fragmentation |
Metrics
With the default metrics feature, wireframe records through the metrics crate, so any recorder installed by the application receives them. With the feature off, the recording helpers become no-ops, so instrumentation can stay in place. An exporter such as metrics-exporter-prometheus is the application’s own dependency. The names are public constants:
assert_eq!(
metrics::FRAMES_PROCESSED,
"wireframe_frames_processed_total"
);
assert_eq!(
metrics::DECODE_REJECTIONS,
"wireframe_decode_rejections_total"
);
| Name | Kind | Records |
|---|---|---|
wireframe_frames_processed_total | Counter | Frames, by direction |
wireframe_errors_total | Counter | Errors, by kind |
wireframe_connection_panics_total | Counter | Panicking connection tasks |
wireframe_decode_rejections_total | Counter | Decode limit rejections, by path and reason |
wireframe_preamble_rejections_total | Counter | Rejected preambles |
wireframe_app_response_sends_total | Counter | Response send attempts, by outcome |
wireframe_application_preparations_total | Counter | Preparation attempts, by outcome |
wireframe_application_preparation_duration_seconds | Histogram | Preparation time, by outcome |
wireframe_prepared_connection_uses_total | Counter | Connections handled by a PreparedApp |
wireframe_server_startup_failures_total | Counter | Failed server starts |
wireframe_server_startup_duration_seconds | Histogram | Server start time |
wireframe_server_accept_loops_exited_total | Counter | Accept loops that have exited |
wireframe_server_supervisor_cancellations_total | Counter | Supervisor cancellations |
wireframe_server_supervisor_abnormal_terminations_total | Counter | Unexpected supervisor exits |
wireframe_connections_active | Gauge | Accepted connections, from accept until the task ends, and actors run by hand |
wireframe_codec_errors_total | Counter | Decoder failures, by error_type and the recovery_policy applied |
wireframe_response_cancellations_total | Counter | Streamed replies cut short, by reason |
wireframe_push_writes_abandoned_total | Counter | Pushed frames dropped before delivery, by reason |
wireframe_push_rate_limited_total | Counter | try_push calls refused by the rate limit |
wireframe_push_drops_total | Counter | Pushes lost to a drop policy, by policy and outcome |
wireframe_streaming_body_outcomes_total | Counter | Streaming body events, by outcome |
wireframe_streaming_body_bytes_queued | Gauge | Queued and reserved request body bytes |
wireframe_streaming_bodies_parked | Gauge | Completed messages waiting behind a live request body |
The streaming body metrics are process-wide. Read queued bytes alongside the admission_timeout outcome to diagnose body back-pressure. The users’ guide lists the outcomes and associated log fields.
Client pools add their own wireframe_pool_* metrics; wireframe_pool_connection_discards_total is the one to watch for socket churn. The users’ guide lists them.
Logging goes through both log and tracing. Install a subscriber or logger, from the application’s own dependencies, to see the warnings for unrouted messages, rejected frames, and preamble errors; wireframe installs nothing itself, so without one they are lost.

