Skip to main content

Module deadline

Module deadline 

Source
Expand description

The read deadline: how long a connection may hold this server without a request read in full on it (I2156).

tiny_http reads every request head on a thread of its own pool and never times a read out, and the body is read by the thread answering the request. A client that opens a connection and sends one byte a second therefore holds a thread forever; enough of them hold every request handler, and past super::server::MAX_HANDLERS the probe a client sends before taking the lease over waits behind them. tiny_http never hands its socket out, so the deadline is kept from beside it: a sweeper lists this process’s descriptors, keeps the ones connected to the served address, and shuts down every connection that has been waiting for a request, or reading one, for longer than the deadline. A connection whose request is being answered is never closed: handler time is bounded by moving it off the workers, not by cutting a tool call short.

The deadline also bounds a wait it does not cause. tiny_http keeps a pool thread on each connection for as long as it lives, and a connection that arrives in a burst can be queued in that pool until one of its threads is free; behind slow clients, that was never. Now it is at most the deadline, when a slow client’s thread is released.

Unix only: elsewhere the descriptors cannot be listed, nothing is closed, and the counters stay at zero.

The lifecycle, from a process’s side: nothing is reported until a server starts, and from then on the counters only grow.

use majordomus_cli::http::deadline;
use majordomus_cli::http::{server, Router};
assert_eq!(deadline::counts(), None, "no server, nothing to report");
let running = server::bind("127.0.0.1", 0).unwrap().start(router());
// the deadline the server holds connections to is the declared one
let counts = deadline::counts().expect("a serving process reports its counts");
assert_eq!(
    counts.read_deadline_seconds,
    majordomus_cli::lease::timings().read_deadline.as_secs()
);
running.stop();

Structs§

ConnectionCounts
What this process’s HTTP server has done to clients that held a connection without using it: the deadline it applies and what that deadline cost, since the process started. Absent while this process serves no HTTP.

Functions§

counts
The counters of this process’s HTTP server, or nothing when it serves none.