Skip to content

chore: sync quinn main - #823

Merged
divagant-martian merged 92 commits into
mainfrom
sync-upstream
Oct 16, 2026
Merged

divagant-martian merged 92 commits into
mainfrom
sync-upstream

Conversation

@divagant-martian

@divagant-martian divagant-martian commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Syncs quinn main up to commit quinn-rs/quinn@ba18f6c which is abit over two month of incoming updates

API Changes

Deprecates UdpSocketState::send so it includes a version bump

Notes & open questions

Missing breaking changes again

Change checklist

  • Self-review.
  • Documentation updates following the style guide, if relevant.
  • Tests if relevant.
  • All API changes documented.
  • This PR was created by a human that thought critically about the
    proposed change and wrote an as clear and concise description as
    they could.
  • This PR isn't slop, and is carefully crafted to do have the
    intented effect.
  • cargo make passes locally.

dependabot Bot and others added 30 commits June 22, 2026 13:15
Bumps [actions/checkout](https://github.com/actions/checkout) from 6 to 7.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v6...v7)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.102 to 1.0.103.
- [Release notes](https://github.com/dtolnay/anyhow/releases)
- [Commits](dtolnay/anyhow@1.0.102...1.0.103)

---
updated-dependencies:
- dependency-name: anyhow
  dependency-version: 1.0.103
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [rustls](https://github.com/rustls/rustls) from 0.23.38 to 0.23.41.
- [Release notes](https://github.com/rustls/rustls/releases)
- [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md)
- [Commits](rustls/rustls@v/0.23.38...v/0.23.41)

---
updated-dependencies:
- dependency-name: rustls
  dependency-version: 0.23.41
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [rustc-hash](https://github.com/rust-lang/rustc-hash) from 2.1.2 to 2.1.3.
- [Changelog](https://github.com/rust-lang/rustc-hash/blob/main/CHANGELOG.md)
- [Commits](rust-lang/rustc-hash@v2.1.2...v2.1.3)

---
updated-dependencies:
- dependency-name: rustc-hash
  dependency-version: 2.1.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [aws-lc-rs](https://github.com/aws/aws-lc-rs) from 1.16.3 to 1.17.1.
- [Release notes](https://github.com/aws/aws-lc-rs/releases)
- [Commits](aws/aws-lc-rs@v1.16.3...v1.17.1)

---
updated-dependencies:
- dependency-name: aws-lc-rs
  dependency-version: 1.17.1
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [rustls-pki-types](https://github.com/rustls/pki-types) from 1.14.0 to 1.15.0.
- [Release notes](https://github.com/rustls/pki-types/releases)
- [Commits](rustls/pki-types@v/1.14.0...v/1.15.0)

---
updated-dependencies:
- dependency-name: rustls-pki-types
  dependency-version: 1.15.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
The GSO-disable path just above already treats EIO like EINVAL, but the
cmsg fallback (sendmsg_einval, which stops setting the ECN IP_TOS cmsg)
only triggered on EINVAL. Some Android kernels return EIO for the ECN
cmsg, so the fallback never ran and every sendmsg kept failing.
`AsyncUdpSocket::poll_recv` discarded every error the socket returned and
re-polled. On the tokio runtime that is a busy loop: `try_io` clears readiness
only for `WouldBlock`, so any other error leaves readiness asserted,
`poll_recv_ready` completes at once, and the recv fails again — a synchronous
loop inside a single poll, with no yield point. Seen on iOS as ~1.07M
`recvmsg`/s all returning `ENOTCONN` after the bound interface went away,
pegging a core and starving every other task on a current-thread runtime.

It also left `RecvState::poll_socket`'s error handling unreachable for both
bundled runtimes: neither the `ConnectionReset => continue` retry nor the
`Err(e) => return Err(e)` teardown — present since 71927fb — can ever run,
because `poll_recv` never yields `Ready(Err(_))`.

Return the error instead, in the tokio and smol sockets alike, and let
`poll_socket` decide what is fatal.
Bumps [tinyvec](https://github.com/Lokathor/tinyvec) from 1.11.0 to 1.12.0.
- [Changelog](https://github.com/Lokathor/tinyvec/blob/main/CHANGELOG.md)
- [Commits](Lokathor/tinyvec@v1.11.0...v1.12.0)

---
updated-dependencies:
- dependency-name: tinyvec
  dependency-version: 1.12.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>
…rnel bug

Non-blocking sendmsg/sendmsg_x on Apple platforms can permanently return with EWOULDBLOCK when a datagram plus its cmsg lands just under `SO_SNDBUF`. Enforce a safe `SO_SNDBUF` floor on socket creation and resize.

See https://feedbackassistant.apple.com/feedback/23671230
Bumps [serde_with](https://github.com/jonasbb/serde_with) from 3.20.0 to 3.21.0.
- [Release notes](https://github.com/jonasbb/serde_with/releases)
- [Commits](jonasbb/serde_with@v3.20.0...v3.21.0)

---
updated-dependencies:
- dependency-name: serde_with
  dependency-version: 3.21.0
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <[email protected]>
We're currently not handling ICMPv4 Fragmentation Needed and ICMPv6
Packet Too Big (PTB) messages since they cannot be authenticated, and
Datagram Packetization Layer Path MTU Discovery (DPLPMTUD) works without
it anyways.

A dedicated check for this type became necessary due to a recent change
in how internal errors originating from recvmsg are exposed to the
caller as errors (rather than letting the runtime silently retry the
read).

Fixes #2733.
`PacketSpace::sent_packets` is inserted on every sent packet and removed
on ACK/loss. Because packet numbers are monotonic, a `BTreeMap` spends
most of its cost allocating and freeing a tree node per entry: heap
profiling a loopback bulk transfer attributes ~36% of all allocations
(and ~99% of BTreeMap-node allocations) to this one map, even though only
a few dozen entries are live at once — it is allocation churn, not
residency.

Replace it with `SentPackets`, a sparse ring buffer indexed by
`packet number - offset`. Insert and lookup are O(1) with no per-packet
allocation; skipped packet numbers leave vacant slots, and vacant slots
at the front are reclaimed as the low end is acknowledged. Iteration
order and range/gap semantics match the previous `BTreeMap`, so ACK and
loss detection are unchanged.

Fixes #2720.
`PacketSpace::has_in_flight` scanned `sent_packets` on every PTO
computation. Track the number of in-flight (`size != 0`) entries on insert
and remove instead, so the query is a single comparison. This was the last
per-poll scan of the sent-packet window, so `values` is no longer needed.
RecvState::poll_socket copied every received datagram into its own freshly
allocated BytesMut. Instead, copy the batch into a single reusable buffer and
split each datagram off as an owned slice that shares that allocation. reserve
reclaims the buffer once the previous batch's slices have been dropped, so it
only reallocates while datagrams are still in flight. The rest of the receive
path stays zero-copy.

Measured with dhat on a 200 MiB loopback bulk transfer, the receive-path
allocations drop from ~38.6k blocks to ~6.7k. Loopback throughput is unchanged
within noise, since it is bound by crypto/CPU rather than allocation there.
Explain at the copy site why datagrams are copied into a reusable BytesMut
rather than read directly into it: recv_buf is allocate-once scratch, while
the BytesMut is handed out to connections and cannot be reused across polls
once a slice is still in flight.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Bumps [thiserror](https://github.com/dtolnay/thiserror) from 2.0.18 to 2.0.19.
- [Release notes](https://github.com/dtolnay/thiserror/releases)
- [Commits](dtolnay/thiserror@2.0.18...2.0.19)

---
updated-dependencies:
- dependency-name: thiserror
  dependency-version: 2.0.19
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 6 to 7.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](actions/setup-node@v6...v7)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '7'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Bumps [rustls](https://github.com/rustls/rustls) from 0.23.41 to 0.23.42.
- [Release notes](https://github.com/rustls/rustls/releases)
- [Changelog](https://github.com/rustls/rustls/blob/main/CHANGELOG.md)
- [Commits](rustls/rustls@v/0.23.41...v/0.23.42)

---
updated-dependencies:
- dependency-name: rustls
  dependency-version: 0.23.42
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
ojhermann and others added 10 commits October 15, 2026 15:46
…uffer (#823)

Explain at the copy site why datagrams are copied into a reusable BytesMut
rather than read directly into it: recv_buf is allocate-once scratch, while
the BytesMut is handed out to connections and cannot be reused across polls
once a slice is still in flight.

(cherry picked from commit 5c9ffd5)
A native cmsg buffer is only guaranteed to be aligned for the control
message header. On musl that header is less strictly aligned than some
payloads (e.g. `libc::timespec`), so decoding through an aligned
`ptr::read` is unsound; read it unaligned instead.

(cherry picked from commit d9919a1)
(cherry picked from commit ba29458)
The `send` API handles IO errors by logging them. This is an error
handling policy that can just as easily be implemented by consumers as
well.

More importantly, upcoming features like the support for partial sends
conflicts with this API because we cannot return a truthful `Ok(())`
value when silencing an error.

To preserve the original behaviour of logging non-fatal IO errors, quinn
itself is transitioned to rate-limit the logging of errors inside each
`UdpSenderHelper`. This is a slight change in behaviour. Previously, the
errors were rate-limited per socket whereas now the errors are
rate-limited per `UdpSenderHelper`. Several of those share a single
socket.

(cherry picked from commit 148d760)
`Connection::new` only queried `cid_len()` and `cid_lifetime()` on the
generator; it never minted a CID. Take the two values directly.

(cherry picked from commit c9008d0)
The locally-created-CID index (`connection_ids`) mapped directly to
`ConnectionHandle`, while the initial-DCID index already used
`RouteDatagramTo`. Store `RouteDatagramTo` in `connection_ids` too:
`new_cid` takes the route to register, and `ConnectionIndex::get`
returns it without re-wrapping.

No behavior change (every route is still `RouteDatagramTo::Connection`);
this is what later lets a locally-created CID point at an in-flight
`Incoming`.

(cherry picked from commit 97a5386)
…#823)

The `TooManyChunks` cap was only checked inside the over-allocation
branch of `Assembler::insert`, and only for the tail push. A peer
sending many small gapped STREAM frames can keep over-allocation below
the defragmentation threshold while the chunk count grows to the stream
flow-control limit, and frames handled entirely by the unordered dedup
loop return before the check runs. Either way the buffered chunk count
is unbounded, which is the memory-exhaustion class the original advisory
addressed.

Check the chunk count after every push, including the unordered dedup
loop, and compact once it passes a watermark above the cap so that a
flood of mergeable (duplicate or contiguous) frames cannot force a
defragmentation on every frame. A stream is rejected once compaction
cannot bring the distinct span count back to the cap. Buffered chunks
are bounded at O(twice the cap); the count is re-checked after every
insert, though a single unordered frame may transiently push a few
chunks past the watermark before that check.

(cherry picked from commit 4b88c94)
@divagant-martian

divagant-martian commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

@flub & @matheus23 I want to get the current progress merged. All the changes you requested are done. After you approve I'll record the merge from quinn and merge to main. The next commit needs a lot adaptations so I'm doing that separate.

Also the failures come from main

@matheus23 matheus23 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a nit, but only if time permits.

Comment thread noq-proto/src/connection/spaces.rs Resolved
divagant-martian and others added 11 commits October 16, 2026 10:03
Extract Retransmits::retire_cids, bounding pending_retired regardless of
which branch queues a retirement. The Ok(Some(..)) branch already enforced
MAX_PENDING_RETIRED_CIDS; the Err(InsertError::Retired) branch pushed
directly onto retire_cids, bypassing the cap entirely. Route both call sites
through the shared, bounded method instead of duplicating the check.
…ing loss burst (#823)

Fixes #2791.

`BlackHoleDetector::on_non_probe_acked` returned early for any packet no
larger than `acked_mtu`, so once a full-size packet had been
acknowledged, `largest_post_loss_packet` never advanced again as long as
every packet was full-size — the steady state of a bulk transfer.
Because `on_ack_received` registers acknowledgments before running loss
detection, one ACK that confirms newer full-size packets and reveals ≥
`BLACK_HOLE_THRESHOLD + 1` older non-adjacent holes then judged all of
those holes suspicious, even though the same ACK had just shown that
full-size packets still get through. On a lossy path this turns ordinary
congestion loss during a download into a black hole verdict and a drop
to `min_mtu` (details and production numbers in #2791).

The change: when `len == acked_mtu`, keep `acked_mtu` but advance
`largest_post_loss_packet` to the newer packet number, so loss bursts
that precede that delivery are non-suspicious under the existing rule
while losses transmitted after the last delivery remain suspicious. This
matches the design in #1855 ("larger than any more recently acknowledged
packet").

The new unit test fails on `main` before the change and passes after;
the existing black hole tests, including
`blackhole_after_mtu_change_repairs_itself`, still pass.

On 0.11.x this fix alone is not sufficient because `finish_loss_burst`
there still uses strict `<` (fixed on `main` by #2400 but not
backported); I have a branch with #2400's two commits cherry-picked plus
this one, all tests green
(https://github.com/vcarus/quinn/tree/bhd-0.11.x), if you'd like a
backport PR.

Co-authored-by: vcarus <[email protected]>
(cherry picked from commit b0afb6e)
Expose the bandwidth estimate from the congestion controller.

With Reno/CUBIC we can compute this from window / RTT, but for BBR we
need the actual estimate from the CC algorithm.

(cherry picked from commit 766cca4)
… blocked (#823)

The commit cherry-picked by the current one fixes a bug in quinn that we
had already solved in noq. The cherry-pick limits the brought changes to
adding the test.

Fixes #2785.

Calling `close()` while the congestion window is full never gets
CONNECTION_CLOSE onto
the wire. The gate in `poll_transmit` classifies the packet by the
stream frames still
pending in the space, but a closing connection will never send those —
the packet it
actually builds is just ACKs + CONNECTION_CLOSE. And once closed nothing
can reopen the
gate: incoming ACKs aren't processed anymore so in-flight bytes never
drain, and
`close_common()` stopped the loss timers so the `loss_probes` bypass
never fires. The
peer just sits there until its idle timeout.

We hit this cancelling a bulk sender mid-transfer — captures showed zero
close datagrams
leaving, every time the cancel landed on a saturated window.

Fix is to exempt close packets from the gate, same idea as the existing
tail-loss-probe
exemption on the line above: the close packet isn't congestion
controlled, and blocking
it can deadlock.

The new test saturates the window with unacked data, closes, and checks
the peer sees
the right close code/reason within a few PTOs instead of idle-timing
out. Fails on main,
passes with the change.

(cherry picked from commit e556fde)
#823)

RFC 9000 §12.4 Table 3 marks CONNECTION_CLOSE `ih01`, where `ih` means
"Only a CONNECTION_CLOSE frame of type 0x1c can appear in Initial or
Handshake packets", and §12.4 requires PROTOCOL_VIOLATION on receipt of
a frame in a packet type that is not permitted.

quinn applies this on the send path: `poll_transmit` rewrites an
application close into a 0x1c close with APPLICATION_ERROR for non-Data
spaces, per §10.2.3. The receive path does not.

Two changes, one per direction:

1. `process_early_payload` accepted both close types. Initial packets
are protected with keys derived from the cleartext original DCID, so
anyone observing the handshake can forge one and hand the application an
arbitrary application error code and reason phrase. Now only 0x1c is
accepted; 0x1d falls through to the existing "illegal frame type in
handshake" arm.

2. The 0-RTT filter rejected a 0x1d close. §12.5 lists the frames that
cannot appear in 0-RTT as ACK, CRYPTO, HANDSHAKE_DONE, NEW_TOKEN,
PATH_RESPONSE and RETIRE_CONNECTION_ID. CONNECTION_CLOSE is not in that
list, and §19.19 says 0x1d "can only be sent using 0-RTT or 1-RTT
packets". This turned a peer's clean application close into a transport
error.

Test: `application_close_in_initial_is_rejected` builds an
Initial-key-protected packet containing a 0x1d close and checks the
connection fails with PROTOCOL_VIOLATION rather than surfacing
`ApplicationClosed`. It fails before this change. There is no test for
the 0-RTT half because quinn never emits such a packet itself:
`poll_transmit` skips the Data space for a close unless 1-RTT keys
exist, so it cannot be reproduced quinn to quinn.

`cargo test -p quinn-proto` passes (294), `cargo test -p quinn` passes
(23), fmt and clippy are clean.

(cherry picked from commit d5d5b97)
…823)

Closes #2739 via option 1.

Chunks now live in a `VecDeque` ordered by offset instead of a
`BinaryHeap`:
- `read` takes from the front
- an in-order frame appends to the back
- a frame below everything buffered pushes to the front; anything else
is placed by binary search

Two orderings are now explicit:
- a partial read can advance the front chunk past a neighbour it
overlaps
- `defragment` has to emit the accumulated chunk before a later
defragmented one

Tie order stays unspecified, as it was under the heap.

Measurements
- nanoseconds per frame
- 1200 byte frames
- best-of-N with N sized to at least 300ms per case
- median of five processes, or three for the bounded-read and 32 chunk
rows
- binaries interleaved

Note: the figures I posted in the issue were best-of-40 and too noisy to
use, so please ignore them.

| case | BinaryHeap | VecDeque |
| --- | --- | --- |
| in-order, 1 chunk buffered | 52.6 | 31.5 |
| in-order, 25 chunks buffered | 64.1 | 31.5 |
| in-order, 127 chunks buffered | 84.7 | 31.8 |
| in-order, 1000 chunks buffered | 108.4 | 31.9 |
| in-order, 127 buffered, 1024 byte reads | 106.6 | 55.8 |
| descending offsets | 36.1 | 18.8 |
| gapped inserts mid-range, 32 buffered | 37.1 | 68.9 |
| gapped inserts mid-range, 500 buffered | 38.5 | 187.2 |
| gapped inserts mid-range, 1500 buffered | 37.1 | 423.9 |
| one `defragment` call at 1900 chunks | 179 us | 39 us |

Summary
- about 19ns of each in-order row (in both columns) is `Bytes::clone`
plus the `Chunk` drop
- the heap slows down as the buffer deepens and the deque does not
- the bounded-read row exercises the partial-read path, where the new
code restores ordering by hand; it costs nothing measurable, since the
guard returns immediately on in-order data

The gapped rows are what it costs: the deque is already the slower of
the two by about 32 buffered chunks; `COMPACT_THRESHOLD` holds the
buffer to 2048 chunks of 56 bytes, so the shift should stay under ~57KB;
in unordered mode the dedup loop can do several of these inserts for one
frame, which I measured at parity with the heap.

`defragment` gets cheaper because its input is already ordered, so it no
longer sorts.

(cherry picked from commit ba18f6c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.