Skip to content
wireframe home
Menu

Running in production

The server is a typestate, a pool of workers, and an accept loop that backs off when the listener fails.

wireframe 0.4.0-alpha1 · samples verified 2026-12-02

Plate 25 · Civic setting Maintenance. A wrench and hammer form a maintenance emblem. It stands for care, not for a support offering.

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.

production.rs · configure, bind, run, stopWorking example
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 accept fails, as it does when the process runs out of file descriptors, a worker waits and retries with exponential backoff between initial_delay and max_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:

production.rs · a factory that failsWorking example
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.

production.rs · a drain with a deadlineWorking example
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

SettingDefaultEffect in 0.4.0-alpha1
buffer_capacity1,024 bytesFrames over the limit are a decoder error, and the connection closes
read_timeout_ms100 msA housekeeping interval: when it elapses with no frame, expired partial messages are purged and the connection keeps waiting
Deserialization failures10The connection closes; a fully dispatched message resets the count
preamble_timeout10 secondsBounds 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 limit16 MiBBounds peer-declared container lengths in the bundled decoders; fixed
Memory budgets16, 64, 64 × frame limitReads slow at 80% of the aggregate cap and the connection closes past it; see memory budgets
FragmentationOffSee 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:

production.rs · metric namesWorking example
assert_eq!(
    metrics::FRAMES_PROCESSED,
    "wireframe_frames_processed_total"
);
assert_eq!(
    metrics::DECODE_REJECTIONS,
    "wireframe_decode_rejections_total"
);
NameKindRecords
wireframe_frames_processed_totalCounterFrames, by direction
wireframe_errors_totalCounterErrors, by kind
wireframe_connection_panics_totalCounterPanicking connection tasks
wireframe_decode_rejections_totalCounterDecode limit rejections, by path and reason
wireframe_preamble_rejections_totalCounterRejected preambles
wireframe_app_response_sends_totalCounterResponse send attempts, by outcome
wireframe_application_preparations_totalCounterPreparation attempts, by outcome
wireframe_application_preparation_duration_secondsHistogramPreparation time, by outcome
wireframe_prepared_connection_uses_totalCounterConnections handled by a PreparedApp
wireframe_server_startup_failures_totalCounterFailed server starts
wireframe_server_startup_duration_secondsHistogramServer start time
wireframe_server_accept_loops_exited_totalCounterAccept loops that have exited
wireframe_server_supervisor_cancellations_totalCounterSupervisor cancellations
wireframe_server_supervisor_abnormal_terminations_totalCounterUnexpected supervisor exits
wireframe_connections_activeGaugeAccepted connections, from accept until the task ends, and actors run by hand
wireframe_codec_errors_totalCounterDecoder failures, by error_type and the recovery_policy applied
wireframe_response_cancellations_totalCounterStreamed replies cut short, by reason
wireframe_push_writes_abandoned_totalCounterPushed frames dropped before delivery, by reason
wireframe_push_rate_limited_totalCountertry_push calls refused by the rate limit
wireframe_push_drops_totalCounterPushes lost to a drop policy, by policy and outcome
wireframe_streaming_body_outcomes_totalCounterStreaming body events, by outcome
wireframe_streaming_body_bytes_queuedGaugeQueued and reserved request body bytes
wireframe_streaming_bodies_parkedGaugeCompleted 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.