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:
To address warnings revealed with
`.enableExperimentalFeature("StrictConcurrency=complete"),` in Swift 5.8
Modifications:
* Numerous protections of state in tests
* Make the multiplexer instances explicitly loop bound
* Update channel initializers to be marked as Sendable
* Mark error backing storage types as unchecked sendable
Result:
Better thread safety
Motivation:
#fileID introduced in Swift 5.3, so no longer need to use #file anywhere
Modifications:
Changed #file to #filePath or #fileID depending on situation
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:
The OutboundFlowControlBuffer is responsible for managing DATA and
HEADERS frames for all streams in order to ensure that we obey HTTP/2
flow control rules, even when users don't. This object is therefore on
the data path for the vast majority of frames, and is extremely
performance sensitive.
Unfortunately, the current algorithm has some nasty performance cliffs.
Right now it has the awkward property of making flushes take an amount
of time linear in the number of streams on the connection, not the
number of streams that had had frames sent on them. The result is that
connections with highly parallel numbers of streams see extremely poor
performance when flushing, a problem that is exacerbated if other parts
of the HTTP/2 stack fail to coalesce those flushes.
We can clean this up in a few ways, but the easiest way is to just keep
track of which streams have done I/O since the last flush. While we're
there, we can make a few other optimisations to ensure we only flush
data on streams we are actually processing, to further reduce the risk
of wasting our time processing unnecessary work.
Modifications:
- Add a Set to keep track of where we've done writes since the last
flush.
- Streams whose flow control window goes to zero stop being writable.
- Cheaper and more accurate calculation of zero-length writes, which
avoids the possibility of awkward stalls with zero-length DATA frames
and END_STREAM.
- Stop doing math about the number of flushed bytes, we don't use that
information any more.
Results:
An approximately 10% performance gain on the 100 concurrent streams
server-only benchmark. The relative performance gain shifts with the
number of active streams, but it should be positive in all cases.
Motivation:
Without knowing where an error was thrown it can be unnecessarily
difficult to work out the reasons an application ended up in an error
state.
Modifications:
- Add a 'file' string to each of the 'NIOHTTP2Errors' denoting the file
and line where an error was created
- Add static methods to create errors to 'NIOHTTP2Errors' defaulting
file and line, this is unfortunately necessary as defaulting file and
line in the `init` makes the defaulted and non-defaulted errors
indistinguishable, and the compiler will pick the one with fewest
defaulted values.
- Add equatable conformance manually so as to ignore 'file'
- Add backing storage to errors which no longer be stored in an existential
container
- Add 'CustomStringConvertible' conformance to the errors using backing
storage so that the 'file' is actually visible when converting the
error
- Deprecate the old `init`s
- Fix all deprecation warnings
Result:
- NIOHTTP2Errors carry a 'file' with them indicating where they were
created
Motiviation:
A few `#file` parameters have been forwarded to (now) `#filePath` ones.
Modification:
- silence the `#file`/`#filePath` warning by adding `(#file)` because we
can't forward them properly right now
(https://bugs.swift.org/browse/SR-12934). That's okay because even on
the Swift master branch, `#file` == `#filePath`.
Result:
No warnings in newer Swift compilers.
Motivation:
In the future we'll want to use PRIORITY frames to provide feedback on
how we emit data. Additionally, RFC 7540 forbids certain kinds of
PRIORITY frame, which right now we tolerate receiving. We can design a
minor PRIORITY shim to ensure that we have a code path for PRIORITY data
to be passed around, and then use this shim to enforce RFC 7540's
requirements.
Modifications:
- Added support for PRIORITY frame data inbound.
- Enforce that frames may not establish self-dependency.
Result:
Better policing of RFC 7540 constraints.
Motivation:
When the remote peer changes SETTINGS_INITIAL_WINDOW_SIZE, this change
affects the flow control window sizes of all existing streams (as though
they were created with this new initial window size). We should respect
those flow control changes.
Modifications:
- Propagated changes in SETTINGS_INITIAL_WINDOW_SIZE.
- Made NIOHTTP2ConnectionStateChange internal.
- Added support for changing initial window size.
Result:
SETTINGS frames that change initial window size now work properly.
Motivation:
When setting the stream window size for a stream which had data but
couldn't write it (because of a zero window size) the stream would be
marked as flushable. Setting the window size to zero again would not
mark it as unflushable. On the following window (non-zero) resize it
would be marked as flushable again. However, since this is preceeded by
an assertion that it wasn't already marked as flushable it would cause a
crash.
Modifications:
- Mark the stream as unflushable if it previously had data which it
couldn't write.
Result:
Fewer crashes
Motivation:
We attempted to use the NIO channel pipeline to spread out the HTTP/2
implementation across a number of channel handlers. Unfortunately, due
to the concerns of reentrancy it's not really safely possible to do this:
it's too easy for the pipeline ordering to become so confused that the
implementation ends up incorrect.
For this reason, we are going to squash together the three handlers that
provide a complete HTTP/2 protocol implementation into just one.
Modifications:
- Move the ConcurrentStreamsHandler and FlowControlHandler into the
HTTP2Handler.
- Update setup and test code accordingly.
Result:
More correct implementation