### Motivation
We currently mitigate against receiving an excessive numbers of
RST_STREAM frames, empty DATA frames, or encountering stream errors in a
given time window.
Receiving excessive numbers of PING, SETTINGS, PRIORITY, ALTSVC, or
ORIGIN frames also results in the endpoint performing unnecessary work.
As such, this PR adds these five frames to the current rate-limiting
mechanism.
### Modifications
- Updated `DOSHeuristics` to also rate-limit PING, SETTINGS, PRIORITY,
ALTSVC, and ORIGIN frames.
- Added a new `controlFrameRateLimit` property to
`NIOHTTP2Handler.ConnectionConfiguration`.
- Plumbed the configuration argument to `NIOHTTP2Handler` initializers.
### Result
Mechanism in place to avoid endpoints from being overwhelmed by
excessive PING, SETTINGS, PRIORITY, ALTSVC, or ORIGIN frames.
Motivation:
`nextStreamToSend()` returned `self.flushableStreams.first`, and since `Set.first` always yields the same stable element, under load the buffer kept handing the whole connection window to one stream while the rest starved to near-zero.
Modifiations:
Rotate through the flushable streams instead of always picking the same one. `flushableStreams` stays the source of truth for membership, and alongside it we keep a queue of those streams (`sendQueue`) in the order to serve them. We pop the front to pick the next stream, and append it to the back once it's been served, so every flushable stream gets a turn per sweep and none can be starved. Both the pop and the append are O(1). Removing a stream from the middle of the queue would be O(n), so we avoid this. A stream that stops being flushable is left as a stale entry and simply skipped when it reaches the front (lazy deletion), with a `queuedStreams` set to stop us ever enqueuing a duplicate.
Motivation:
Swift 6.0 is no longer supported, we should bump the tools version and
remove it from our CI.
Modifications:
* Bump the Swift tools version to Swift 6.1
* Remove Swift 6.0 jobs where appropriate in main.yml, pull_request.yml
Result:
Code reflects our support window.
---------
Co-authored-by: George Barnett <gbarnett@apple.com>
Motivation:
Swift 6.3 has been released, we should add it to our CI coverage.
Modifications:
Add additional Swift 6.3 jobs where appropriate in main.yml,
pull_request.yml
Result:
Improved test coverage.
The codec now caches the most recent outbound frame and only writes it
on flush or when receiving `.end`. This lets us set `endStream=true` on
the final data or headers frame instead of sending a separate empty data
frame.
Changes:
- Introduced `PendingFrameWrite` to cache frame payload and promise
- Modified `processOutboundData` to return optional frames instead of
writing immediately
- Added `flush()` method to both client codecs to handle cached writes
- Promise merging ensures correct completion notification when combining
frames
Motivation:
The nightly CI checks for Integration Tests started failing since run
https://github.com/apple/swift-nio-http2/actions/runs/19310336168/job/55228659542
(on 12 November 2025) due to multiple allocation benchmark tests
exceeding their allocation thresholds.
The date these failures started coincides with [release 2.89.0 of
`swift-nio`](https://github.com/apple/swift-nio/releases/tag/2.89.0). In
particular, all failing allocation benchmarks use `EmbeddedChannel`, and
`EmbeddedChannel` was changed in [a PR contained in that
release](https://github.com/apple/swift-nio/pull/3442) that introduced
some changes leading to greater allocations.
[Another change to
`EmbeddedChannel`](https://github.com/apple/swift-nio/pull/3495) in
`swift-nio`'s latest release
([2.94.0](https://github.com/apple/swift-nio/releases)) has also
increased the number of allocations in benchmarks using
`EmbeddedChannel`.
As such, we should update the allocation thresholds for affected tests
accordingly.
Modifications:
Updated the allocation threshold for all affected tests across all
versions.
Result:
Integration tests should no longer fail.
Motivation:
Swift 6.2 has been released, we should add it to our CI coverage.
Modifications:
Add additional Swift 6.2 jobs where appropriate in main.yml,
pull_request.yml
Result:
Improved test coverage.
Motivation:
Swift 5.9 is no longer supported, we should bump the tools version and
remove it from our CI.
Modifications:
* Bump the Swift tools version to Swift 5.10
* Remove Swift 5.9 jobs where appropriate in main.yml, pull_request.yml
Result:
Code reflects our support window.
---------
Co-authored-by: George Barnett <gbarnett@apple.com>
Motivation:
When the server is in the locally quiescing state and a client attempts
to open a new stream, the connection state machine treats receiving the
headers as a connection error. This results in the connection being
closed and in-flight requests being failed.
This can happen because of the inherent race between the server sending
a GOAWAY frame and the client receiving it, during which time the client
can open a stream not knowing it's doomed to failure.
Rather than the server treating this as a connection error, it should
reject the stream with a RST_STREAM frame and emit a stream error.
Modifications:
- Emit a stream error when receiving HEADERS in the locally quiesced
state
Result:
Better handling of new streams when the server is quiescing
Strictly speaking, a `close` operation can't really fail (except when
the closing mode isn't supported or the channel is already closed). Even
if an error is encountered while closing a channel, or if an error
caused the channel to be closed, the end result is the same: the channel
will be closed.
In this case in particular, when streams are closed from the client
(i.e. by sending a RST_STREAM frame) the `HTTP2StreamChannel` would fail
the channel's `closeFuture`. This isn't appropriate however, as the
channel is successfully closed.
This change stops failing the stream channel's `closeFuture`. Instead,
if the close happens uncleanly, the error will be fired down the
pipeline and the `close` method's promise will be failed.
Motivation:
Complete enablement of all standard GitHub Actions workflows.
Modifications:
Describe the modifications you've done.
Result:
After your change, what will change.
Motivation:
Testing is good - we should check results on PRs.
Modifications:
Add integration tests to PR and scheduled GitHub Actions workflows.
Result:
Integration tests run.
Motivation:
Standardised formatting makes the project cleaner to look at and work
on.
Modifications:
Setup swift-format with the same settings as Swift-NIO
Result:
Common formatting throughout
Motivation:
Want to move away from legacy CI.
Modifications:
Add configuration and update code to use GitHub actions.
Result:
GitHub Actions can be used for basic CI.
Allocation tests currently use a func that takes a promise to create the stream multiplexer.
However, we also provide a different API that doesn't require a promise and instead returns an `EventLoopFuture<Channel>`.
We don't currently have allocation tests for the latter, so this PR duplicates the current H2 tests but uses the non-promise API to create the multiplexer.
I also had to add a new method on the old H2 multiplexer to conform to a test protocol.
Motivation:
Increase allocation test coverage to encompass new HTTP2Handler direct stream multiplexing.
Modifications:
- Duplicate existing relevant allocation tests
- Introduce a new test for inline and legacy modes which creates multiple streams and then performs many requests on each. This is to give an indication of the performance change through many requests and window update frames.
Result:
More allocation test coverage.
Motivation:
To justify performance changes we need to measure the code being
changed. We believe that `HPACKHeaders.subscript(canonicalForm:)` is a
little slow.
Modifications:
- Add allocation and performance tests for fetching header values in
their canonical form
Results:
More benchmarks.
Motivation:
With NIO 2.32.0 we broke the core NIO module up into modules that split
apart the POSIX layer and the core abstractions. As a result, this
package no longer needs to express a hard dependency on the POSIX layer.
Modifications:
- Rewrote imports of NIO to NIOCore.
- Added NIOEmbedded imports where necessary in tests.
- Note that the main modules still depend on NIO, which is necessary
for backwards-compatibility reasons. This dependency is unused.
Result:
No need to use NIOPosix.
Motivation:
Some of the allocation counting tests used frame-based stream channels
rather than the frame payload based ones. These were deprecated some
time ago.
Modifications:
- Update test handlers to be `HTTP2Frame.FramePayload` based
- Update the 'create_client_stream_channel' test to count streams rather
than summing their stream ID (as stream IDs aren't assigned until the
stream channel delivers pending writes for the first time).
- Update allocation limits
Result:
Allocation counting tests don't use deprecated APIs.
Motivation:
SwiftNIO 2.27.0 added synchronous channel options. We can use these if
available when creating a stream channel to avoid a future allocation.
Modifications:
- 'getAutoReadFromParent' is synchronous when possible and now takes a
closure to handle the result.
- Update allocation counts (and sort them to make updating them easier,
this also includes switching the order we run test_1k_requests
interleaved and noninterleaved)
Result:
Fewer allocations.
Motivation:
We don't have any benchmarks or alloc counter tests for doing stream
teardown with GOAWAY frames. While this isn't a terribly hot code path
and isn't terribly performance heavy with allocations, it's good to have
more data here.
Modifications:
- Write benchmarks and alloc counter tests that tear down many streams
with GOAWAY.
Result:
Better testing and alloc counter.
Motivation:
Performance benchmarking wants accurate numbers, and a wide range of
possible benchmarks. One way to get somewhat more accurate numbers is to
use a tool like Cachegrind to measure the instruction counts of a
program. Cachegrind allows us to isolate a number of noise-introducing
effects, as "number of executed instructions" is a much more stable
number than how long a program takes to run.
When running under cachegrind we want to change the way our performance
benchmarks work. Instead of running lots of times to try to average out
noise, we only want to run once to save ourselves time, as the benchmark
itself should be drastically more stable.
While we're here, let's add some much more isolated benchmarks than our
current "make lots of streams" benchmark. This is basically the same
logic, but it does less of NIO and so makes the impact of NIOHTTP2
substantially more prominent.
Modifications:
- Added a cachegrind build mode to the benchmarks.
- Added new benchmarks and alloc counters.
Result:
More info
Motivation:
I have suspicions that the allocation counter tests in NIOHTTP2 don't
fail properly, so let's bring the scaffolding up to date.
Modifications:
Update the few local files to the most recent NIO versions.
Result:
Smaller diffs to NIO, maybe better infrastructure?
Motivation:
CI is spitting out a bunch of warnings about 'configureHTTP2Pipeline'
being deprecated; it is called without providing the inbound stream state
initializer. The non-deprecated version requires that this is
explicitly passed as `nil`.
Modifications:
- Explicitly set the 'inboundStreamInitializer' to `nil`
Result:
Fewer warnings.
Motivation:
The 2 to 1 codecs do a number of operations where they "peek" the
pseudo-headers. Each of these operations uses the HPACKHeaders
subscript, meaning that they allocate a temporary array for a field that
can, in a correct request/response, contain only one element. That's
very wasteful!
Modifications:
- Rewrite peekPseudoHeader to iterate instead, avoiding the array.
- Add allocaton counter test.
Result:
4 fewer allocations per HTTP request transformed on the server side,
2 fewer allocations per HTTP response transformed on the client side.
Motivation:
Previously the HTTP2StreamChannel forwarded all frames to the parent
Channel by way of the abstract Channel existential API. While this was
straightforward, it added unnecessary overhead due to the extra pipeline
steps and the extra indirection of the types providing an inlining
barrier.
Given that in #116 we gave the HTTP2StreamChannel a reference to its
parent multiplexer, we may as well take advantage of this and allow
direct calls from the stream channel into the multiplexer.
Modifications:
Avoided calls to parent.write and parent.flush.
Replaced them with a new interface.
Added new allocation test for this path.
Result:
Slightly better performance.
Motivation:
Allocation tests are good :).
Modifications:
Add two allocations tests and NIO's integration test framework.
Result:
Hopefully fewer allocations in the future. And better ways to check what
allocations are happening.