The request pipeline
How a request travels through the transport: which nodes it asks, when it pings and sniffs, and how it ends. Every box below is a type, an enum
value or a method in the code. The behaviour is pinned by the specs in tests/Elastic.Transport.Tests/ClientConcepts/ConnectionPooling and by
the model-based properties in tests/Elastic.Transport.Properties.Tests.
DistributedTransport.RequestCoreAsync binds the configuration, makes sure the pool has been sniffed once if it should
be, then offers nodes one at a time until one succeeds or the budget is spent. What happens on one node is
TryNodeAsync, and its result is a NodeOutcome.
The budget is read from the request's own RequestAttempt at every step. It is never shared with another request.
In code the turn is a walk over NodeStep (SniffIfStale, PingIfDue, Call, TakeOutOfRotation, Settle, Done);
the failure edges above leave through exceptions that RequestCoreAsync classifies. The single-node path is a separate,
shorter loop on purpose: it never pings, sniffs, marks a node dead or alive, and has the one stale-connection retry.
Stop is for failures another node cannot fix: bad credentials (on the ping or on the call), an unrecoverable
pipeline failure, and cancellation. None of them marks the node dead: a node that answered 401 is up, and a caller that went away says nothing about the node it was waiting for.
Only one sniff per pool is in flight at a time; a request that finds one running carries on with the nodes it has.
A sniff of a stale cluster is housekeeping. When it fails, the audit trail records SniffFailure and the request goes on
to the node it was about to use.
A node's health is the NodeHealth union (Components/NodePool/NodeHealth.cs). The four states are the four meaningful
combinations of alive, resurrected and failed attempts.
| State | IsAlive |
IsResurrected (ping first) |
FailedAttempts |
|---|---|---|---|
Untested |
yes | yes | 0 |
Alive |
yes | no | 0 |
Dead |
no | no | 1 or more |
Resurrected |
no | yes | 1 or more, kept so back-off continues |
Transitions are a compare-and-swap of the whole state, so two requests failing the same node cannot lose a failure.
A sniff asks nodes for the cluster topology and reseeds the pool. It tries every node in turn and fails only when all of them have failed, except that bad credentials end it at once. A successful sniff during a request asks that request (and only that request) to restart its walk from the new view.
A request ends in one of six ways: Success, Bad Auth, Bad Response, Max Retry, Retry Timeout or Bad Sniff. The red boxes below are those exits. Ping, Sniff Cluster and Bad Response are the steps that are used on the way, and have flows of their own.
DiagramSpec (in tests/Elastic.Transport.Properties.Tests) is these flows written as a small program, and DiagramProperties generates requests (pool kinds, node answers, pings, sniffs, retry and time budgets) and checks that the transport makes the same calls and ends the same way, for the sync and the async path.
Select node is NextNode: the pool view hands out alive nodes, and dead ones that are due for another try. The budget is MaxRetries + 1 attempts, where MaxRetries is the configured value, or every node of the pool when none is configured, and never less than the pool allowed when the request started. The elapsed time is read against MaxRetryTimeout with a 2% margin.
Retriable means an answer another node might not give. A 400 or a 500 is not: the response is returned as the answer of the node that gave it. With ThrowExceptions on, it is the exception of the same name.
A sniff that fails the request on startup ends it as Bad Sniff (CouldNotStartSniffOnStartup). A sniff in the middle of a request, after a failed node or of a stale cluster, is housekeeping: the audit trail has SniffFailure, and the request goes on with the nodes it has.
The back-off grows with the failed attempts, from DeadTimeout up to MaxDeadTimeout, and a node that comes back is pinged first (Resurrected, see one node's health).
- The retry budget. With no
MaxRetriesconfigured, a request may try every node of the pool, however many it has. A configuredMaxRetriesis the budget. - Stale cluster information is checked before every node, the first one included.
- A sniff in the middle of a request is housekeeping. When it fails, the audit trail has
SniffFailureand the request goes on with the nodes it has. Only a sniff on startup that fails ends the request, as Bad Sniff. - A sniff that lists no nodes is an answer: the pool keeps the nodes it has.
- A sniff asks the nodes in rotation. A dead node is not asked, unless all of them are. Bad credentials in a sniff end it as Bad Sniff, with the bad credentials as the cause.
- A node that answers 401 is up. It stays in rotation, and the request ends as Bad Auth (
BadCredentialsNodeHealthTests). - A failed ping takes the node out of rotation, and the sniff that may follow does not ask that node again.
- The exit says what ended the request. A
400, a500or bad credentials end it as the answer of the node that gave it, however many nodes were tried and however long it took. Max Retry and Retry Timeout are reported only when the retries or the time did run out. - Max Retry is also the exit of a request that runs out of nodes after
MaxRetriesattempts, one fewer than its budget ofMaxRetries + 1. A pool of dead nodes, where one is tried again as a probe, is the case.
Every step above is an event of the audit trail of the response (ApiCallDetails.AuditTrail): SniffOnStartup, PingSuccess / PingFailure, HealthyResponse, BadResponse, BadRequest, MaxRetriesReached, MaxTimeoutReached, SniffSuccess / SniffFailure and the rest of AuditEvent. A node that answered, with any status, is a BadResponse when it was refused, a BadRequest when nothing came back. The trail is on the response of a request whichever step the request ended on, a ping or a sniff as well as a call.