Repository navigation
Sync internal 2026-11-6 - #1113
Merged
drcaramelsyrup merged 16 commits intoNov 9, 2026
Merged
drcaramelsyrup merged 16 commits into
drcaramelsyrup merged 16 commits into
Conversation
This change makes transport acquire read-ahead storage after socket readiness. Full refills reuse their allocation during sustained reads; short refills release it when drained. `Pending`, EOF, errors, and switching to direct reads release empty read-ahead storage. An empty allocation from a full refill can remain if the caller stops reading. We use `BytesMut` and Tokio's `read_buf` to fill spare capacity without zeroing the entire destination. We return allocations directly to the process allocator for reuse. The default transport and HTTP/1 body read buffers are now 32 KiB, which fits jemalloc's default tcache limit. When body scratch storage needs to grow, we allocate the requested capacity instead of geometrically growing a preread allocation past that limit. Existing storage is reused when it has enough capacity. Local testing results showing memory usage per connection: | Body type | Before (KiB) | After (KiB) | | ------------------------ | -----------: | ----------: | | Upstream fixed/chunked | 70.7 | 6.8 | | Upstream close-delimited | 70.5 | 6.6 | | Downstream fixed/chunked | 71.1 | 7.2 | | Downstream short | 7.1 | 7.2 | The large-buffer cases save approximately 64 KiB per waiting connection. Short downstream bodies already used small destinations.
When a custom upstream proxy attempt ends before its response completes, abandon the custom session so it is not left for reuse. This covers a failed join of the forwarding tasks and a failure while the session is being set up. The caller of `proxy_to_custom_upstream` already abandons the session of a failed attempt after a cache fill abandonment or cancellation, and that abandonment outlives the attempt it happened in, so a retried attempt is covered too. Skip the custom proxy's own abandon in that case so a session is abandoned once, and cover each reachable exit with a retried-attempt test.
Read generated bodies through a stream with random read sizes, Pendings, read errors and cancellations, and check the payload, the bytes after the message, and how errors and early ends are reported. cargo test runs fixed seeds; CI runs a longer soak seeded from the pipeline ID.
FixedBuffer copied every request body chunk into a BytesMut growing up to 64 KiB, although that copy is only read on a retry. Keep chunks of 4 KiB or more by reference count and copy smaller ones together, so a small slice does not keep a larger read buffer alive. get_buffer() joins the pieces only when called. Truncation still releases everything.
Code outside pingora-core can now turn DER bytes into a WrappedX509 on both the rustls and s2n backends without reaching for the ouroboros-generated constructor. Bad input comes back as an InvalidCert error instead of a panic. Includes-commit: e57faa8 Replicated-from: #858 Signed-off-by: Shane Utt <shaneutt@linux.com>
X509Certificate::from_der parses one certificate and returns whatever follows it, and WrappedX509::parse dropped that remainder, so a certificate followed by extra bytes was accepted and kept whole as raw_cert. When such a certificate is used as a per-peer CA, the rustls connector passes raw_cert to RootCertStore::add, which rejects trailing data, so the certificate parsed fine and then failed every connection to that peer. Return InvalidCert when any bytes follow the certificate. The s2n backend gets the same check so that both backends accept the same input, and each gets a test.
CURRENT_HANDLE is a ThreadLocal keyed by an id the thread_local crate recycles on thread exit, so a registration outlives the worker that made it and reappears under whichever thread is handed the same id next. A NoStealRuntime built after an earlier one has shut down can therefore start life holding the dead runtime's handles, and every task its workers spawn through current_handle() is canceled the instant it is spawned, on a runtime that is alive and healthy. This is issue #981. Store the owning ThreadId beside the pools. A std::thread::ThreadId is never reused for the life of the process, so the comparison is exact. init_pools() now claims the slot by assignment rather than get_or, so a worker that inherits a recycled id overwrites the stale entry instead of adopting it, and current_handle() falls through to Handle::current() unless the registration belongs to the calling thread. The unwrap() on the pools OnceCell goes with it, since the owner check makes it unnecessary. The added test drives the registration side and fails without the fix. It lives in a file of its own with a single test because it depends on being the only thing in its process allocating thread_local ids. Includes-commit: 08c2f80 Replicated-from: #982
current_handle() looked up a worker's pools in a thread_local::ThreadLocal, which keeps a value after its thread exits and hands the slot to a later thread. That is how a new no-steal worker could pick up the pools of a runtime that had already shut down (#981), and why the previous commit stores the owning ThreadId beside the pools. A std thread_local! drops its value when the thread exits, so a stale registration cannot exist and the owner check goes away. Dropping the value also releases the shut-down runtime's handles when its workers exit, instead of leaving them in recycled slots. The previous commit credits the owner check with making the unwrap on the pools OnceCell unnecessary. It does not: get_pools() fills the cell before any task can reach a worker. current_handle() keeps the fallback to Handle::current() that replaced the unwrap, but only as a defence. thread_local becomes a dev-dependency. Two more single-test files guard against going back to a ThreadLocal registration, in cases the first test does not cover: spawns from a task on a two-worker second runtime must reach both of its workers, and a thread that is not a worker but is handed a recycled thread_local id must get its own runtime.
`Stream` already carries an optional `Tracer` and reports `on_disconnected()` from its `Drop`, but only the upstream connector ever sets it. Downstream connections have no equivalent today: an application implementing `ServerApp` can set `session.tracer` itself once `process_new` hands it the stream, but by then the handshake has already succeeded, so connections that time out or fail during `io.handshake()` are never seen. Counting live downstream connections is therefore not possible for the accept-to-handshake window. Add an optional `Tracer` to `Listeners`, thread it through to each `TransportStack`, and attach a clone of it to every accepted stream the same way `connectors::l4` does for outbound connections: call `on_connected()` right after `accept()` returns, before the TLS handshake, and let `Stream`'s `Drop` report the disconnect. The tracer rides on the L4 stream, which `handshake()` keeps alive in both the plain and the TLS case, so the two calls pair by construction and the whole life of the connection is covered. No new trait, no signature changes, and no behaviour change when no tracer is set, which remains the default. Includes-commit: 0dda18b Replicated-from: #995 Signed-off-by: Shanire <shanire86@gmail.com>
AcceptLimits, set per endpoint with ListenerConfig::accept_limits, bounds the work a server does for connections it cannot serve. All limits are off by default. - handshake_timeout: the handshake timeout (default 60 s, as before). It covers pre-TLS processing and any wait for a TLS offload thread. - max_connections: a cap on open connections, counted from accept until the socket closes. The connection's L4 stream holds its slot, so it counts wherever the stream goes: in a task the application hands it to, or in a TLS offload queue after its handshake timed out. A new connection over the cap is closed right after accept. - max_pending_handshakes: a cap on handshakes that have not finished, including those waiting for a TLS offload thread. A new connection over it is closed right after accept. A short handshake timeout turns connections over faster, so without this cap it can raise the number of handshakes a server starts when it is offered more connections than it can serve. - skip_closed_peers (Linux): close without a handshake a connection whose peer has already closed or reset it. The check runs when the handshake would start, and again when a TLS offload thread starts it, since a client can give up while its handshake waits in the offload queue. AcceptStats counts what the limits do. Each TLS backend gets a crate-private tls_handshake_checked for the offload-thread check; tls_handshake keeps its signature.
HttpPeer::new and HttpPeer::new_mtls now return a Result. Describe when each returns an error and the one case that still panics.
The fixed-seed fuzz cases already run with the tests. Add a step on the latest stable toolchain that runs the ignored soak test with 1,000,000 cases from a seed taken from the workflow run ID, so each run explores different inputs. A failure prints its case seed, and PINGORA_BODY_FUZZ_CASE=<seed> replays it locally.
Install cargo-nextest 0.9.151 and run the workspace tests through it, which is what .config/nextest.toml already expects for the integration binaries that bind fixed ports. Doc tests still run with cargo test, because nextest does not run them. The h2 test that waits on hyperium/h2#983 is excluded with a filter expression instead of --skip.
zaidoon1
approved these changes
Nov 7, 2026
duke8253
approved these changes
Nov 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.