5 Commits
Author SHA1 Message Date
Aryan Shah bf446775a1 Wait for writes to drain before closing in NIOHTTP2ServerConnectionManagementHandler (#582)
### Motivation

`NIOHTTP2ServerConnectionManagementHandler` was derived from the
implementation in
[`gRPC-swift-nio-transport`](https://github.com/grpc/grpc-swift-nio-transport/blob/main/Sources/GRPCNIOTransportCore/Server/Connection/ServerConnectionManagementHandler.swift).

In that implementation, PR
https://github.com/grpc/grpc-swift-nio-transport/pull/183 updated the
way how the channel is closed. The channel is now first half-closed and
then fully-closed in order to allow all pending writes to drain.

This is also applicable in this implementation, so we should apply the
same change here.

### Modifications

Applied the changes verbatim from PR
https://github.com/grpc/grpc-swift-nio-transport/pull/183.

### Result

Pending writes are drained when gracefully shutting down.
2026-11-17 10:10:41 +00:00
Aryan Shah d6f5f25943 Rate-limit PING, SETTINGS, PRIORITY, ALTSVC, and ORIGIN frames (#561)
### 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.
2026-08-18 17:43:05 +01:00
aryan-25 b6571f3db4 Add a server connection manager (#532)
Motivation:

`NIOHTTP2Handler` currently does not support graceful shutdown because
it does not action upon a `ChannelShouldQuiesceEvent` event. See issue
https://github.com/apple/swift-nio-http2/issues/336.

Per the
[comment](https://github.com/apple/swift-nio-http2/issues/336#issuecomment-2252862397)
on that issue,
[`gRPC-swift-nio-transport`](https://github.com/grpc/grpc-swift-nio-transport)
implements this functionality in a separate channel handler, named
[`ServerConnectionManagementHandler`](https://github.com/grpc/grpc-swift-nio-transport/blob/main/Sources/GRPCNIOTransportCore/Server/Connection/ServerConnectionManagementHandler.swift).
We should introduce this to this repo too.

Modifications:

- Added `ServerConnectionManagementHandler` from
`gRPC-swift-nio-transport` with some slight modifications such as
removing gRPC-specific functionality like policing client pings.
- Added a new `configureAsyncHTTP2Pipeline` helper, which takes a
connection manager configuration as an argument and sets the
connection manager up alongside `NIOHTTP2Handler`.

Result:

Addresses issue https://github.com/apple/swift-nio-http2/issues/336.
2026-02-18 08:08:55 +00:00
aryan-25 c1bb956720 Update allocation thresholds (#534)
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.
2026-02-09 12:41:37 +00:00
aryan-25 35b0b8f7e5 Fix bug where client ignores HEADERS frames on open stream when locally quiescing (#445)
Motivation:

Currently, HEADERS frames are ignored by the client on a client-initiated stream after the client sends a GOAWAY.

As per [Section 6.8 (GOAWAY) in RFC 9113](https://httpwg.org/specs/rfc9113#GOAWAY):
_"Once the GOAWAY is sent, the sender will ignore frames sent on streams **initiated by the receiver** if the stream has an identifier higher than the included last stream identifier."_

In this case, the client (sender) should **not** ignore the HEADERS frame as the stream is initiated by the _client_, not the receiver.

Modifications:

Fixed the condition in the `receiveHeaders` function (given `LocallyQuiescingState`) in `ReceivingHeadersState.swift` to work for _both_ the client and server roles -- before this change, the condition is only correct when `self.role == ConnectionRole.server`

Result:

HEADERS frames are not ignored by the client on a client-initiated stream when locally quiescing.
2024-07-18 06:55:30 -07:00