Motivation:
The build_podspec.sh script generates a podspec which requires exact
versions of its dependencies. This very quickly turns into unresolvable
dependency graphs.
Modifications:
- NIO version passed to script must be in the format `MAJOR.MINOR`
- Podspec dependencies are now '>= MAJOR.MINOR', '< MAJOR+1'
Result:
Looser version requirements for podspecs
Motivation:
As part of #202 we added support for configuring the target window size
of stream channels. That was plumbed through into outbound channels, but
we missed the inbound ones, meaning that this only really worked for
clients, not servers. That hardly seems fair!
Modifications:
Pass target window size to inbound channels too.
Result:
We can control target window size of inbound channels.
Motivation:
As Chrome has started GREASEing HTTP/2 settings and frames, we should
ensure that we have tests that explicitly validate that we tolerate
GREASEing these parameters.
A future version of swift-nio-http2 should start emitting GREASE as
well, but for now we'll satisfy ourselves with this.
Two relevant citations:
https://tools.ietf.org/html/draft-bishop-httpbis-grease-00https://bugs.chromium.org/p/chromium/issues/detail?id=1083706
Modifications:
- Added a frame parser test
- Added a end-to-end settings test.
Result:
Validated that GREASE is tolerated.
Motivation:
Sometimes folks will want to print things about the HTTP2StreamChannel,
and we should give them the things we can safely get. We also may want a
shorter log for NIOHTTP2Handler as the standard description, with the
wall of text available in the debug description.
Modifications:
- Conform HTTP2StreamChannel to CustomStringConvertible
- Conform NIOHTTP2Handler to CustomDebugStringConvertible.
Result:
Even better debug info.
Motivation:
All public parts of the Channel protocol, such as isActive, are required
to be thread safe. Unfortunately, we missed a spot with the isActive
bool on HTTP2StreamChannel.
Modifications:
Back the HTTP2StreamChannel.isActive bool with an atomic, and set it on
state change.
Result:
Thread-safety for public readers of channel activity
Motivation:
Infow target window size constrains throughput. The default hardcoded 65535 is low for some use cases and so needs to be configrable. A TODO in the code stated 'Make configurable'.
Modifications:
- In HTTP2StreamMultiplexer, responding to a TODO where stream multiplexer creates a stream channel, created a multiplexr stored property to be used which is set in the default initilaizer.
- In HTTP2PipelineHelpers, added versions of configureHTTP2Pipeline(..) and configureCommonHTTP2ServerPipeline that require an activeTargetWindow arg.
Result:
Clients, such as GRPCClient, can configure pipelines with targetWindowSizes to their liking.
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
Linking to `CONTRIBUTING.md` directly would save readers some time if they'd like to navigate to this file while reading `README.md`.
Modifications:
No functional change, only `README.md` is updated.
Result:
The rendered `README.md` will have a direct link to `CONTRIBUTING.md`.
Motivation:
Sometimes it's useful to be able to print out objects and see their
internal state. Somehow, HTTP2Handler can't do this.
Modifications:
Add a conformance to HTTP2Handler.
Result:
Awesome debugging output.
Motivation:
Applications might want to support H2 (when available) and HTTP1 (as a fallback).
The application logic should not change between the two versions of the protocol
and the code to configure support for both the protocols is boilerplate and can
be provided as an helper function.
Modifications:
This PR adds an helper function to configure HTTP1 or H2 pipelines according to
the protocol negotiated by the TLS handler.
Result:
Applications that need to support clients using both HTTP1 and H2 can
configure their channels by calling `configureCommonHTTPServerPipeline`,
which should reduce the boilerplate they have to write.
Co-Authored-By: Cory Benfield <lukasa@apple.com>
Motivation:
When a window update event is received in the stream channel we notify
the inbound window manager. Doing so may emit a WINDOW_UPDATE frame
to indicate the remote may send us more DATA. However, this happens even
if there are inbound frames waiting to be delivered to the channel. This
may lead to the remote sending us more DATA which we have to buffer
until it is read.
Modifications:
- Update the inbound window manager to track the number of bytes
buffered in the stream channel
- Account for buffered bytes when receiving a new window size event
- Possibly emit WINDOW_UPDATE after unbuffering inbound frames into the
stream channel's pipeline
Result:
The timing of WINDOW_UPDATE frames is better aligned with when frames
are actually read in a stream.
motivation: docs scripts is broken on selinux due to restriction on ssh-agent
changes:
* change the jazzy workspace to a directory accessible by the CI node so we can push from the agent instead of from the docker container
* dont remove older docs when pushing new ones
* add version information and source links
Motivation:
Previously, if we failed in the stream channel initialiser and the
stream channel was closed before finishing the stream channel
initialiser, we would crash on an assertion because `closedWhileOpen`
correctly asserted that it has nothing to do and shouldn't be called.
Modification:
Apart from `.idle` also stop calling `closedWhileOpen` in `.closed` and
`.localActive` because the network actually doesn't think this channel
is open.
Result:
- Fewer crashes
- fixes rdar://59342916
motivation: more secured ci setup
changes:
* enable :z selinux flag on bind mounts so we can enable selinux on ci
* drop potentially exploitable capabilities from docker-compose
* Add a subscript to HPACKHeaders to return the first value with a matching name
Motivation:
In some cases you only expect (or care about) a single value for a
header. However, getting this value without allocating an array or
traversing the whole array requres using first(where:) provided by
Sequence. This is not very ergonomic as it requires users to do the
case-insensitive comparison and then exctact the value from the
HPACKHeader. Additionally, users cannot use NIO HTTP/2s case insensitive
ASCII comparison.
Modifications:
- Provide a first(name:) method on HPACKHeaders which returns the value
from the first header whose name is a case insentive match of the
subscript parameter.
Result:
It's easier to get the first
Motivation:
The code-of-conduct email address is out-of-date.
Modifications:
Update code-of-conduct email address to swift-server-conduct@group.apple.com
Result:
- Code of conduct email address is up-to-date.
Motivation:
Frames that close a stream may consume some of the connection window. We
were not correctly accounting for that in the code, which meant that
frames that carried END_STREAM would not notify the stream multiplexer
that they had consumed connection window space. In the worst cases this
could lead to resource starvation due to consumption of this window
without causing us to emit new WINDOW_UPDATE frames.
Modifications:
StreamClosedEvents should be followed by flow control change events.
Result:
We will correctly update the connection window when a stream is closed.
Motivation:
Newer Swift compilers warn about implicitly tupling the payload of an
enum case whilst pattern matching.
Modification:
Stop using implicit tupling.
Result:
No warnings on newer Swift compilers.
Motivation:
The HTTP/2 RFC does not explicitly forbid sending more than one
RST_STREAM for the same stream. Given that we have seen this behaviour
in the wild we are going to ignore any additional RST_STREAMs.
A further indicative that this is the right call is that the RFC
explicitly mentions that sending RST_STREAMs in the idle state is not
acceptable.
Modifications:
Ignore RST_STREAM frames for streams in the closed state.
Result:
More compatibility.
Motivation:
Having benchmarks for the HPACK encoder and decoder gives us better
insight into their performance. While we have some simple benchmarks in
the XCTests, using the NIO performance tester framework will give us
more insight into what's happening.
While we're here, we can move the Huffman benchmarks out of the unit
tests and into the benchmark suite.
Modifications:
Added encoder, decoder, and huffman benchmarks.
Result:
Better performance numbers.
Motivation:
We have a slow path in compareCaseInsensitiveASCIIBytes. On the server
this path will never be hit as to hit it requires having a
non-contiguous String, so we really really want the compiler to use all
its inlining smarts on the fast path instead. Currently it does, but as
Sequence.elementsEqual is inlinable we need to be sure that doesn't
change.
Modifications:
Force the slow path not to be inlined.
Result:
Guarantees about good inlining.
Motivation:
In many cases it's necessary to be able to do HPACK table lookups to
find only a matching header field name, when it isn't going to be
possible to use a fully indexed header. For example, when using
nonIndexable header fields you cannot use an indexed field value, so
there is no point looking at all the header field values anyway.
While we technically supported this, there were two wrinkles. The first
was that if you attempted to search for a header field without any care
for its name, we'd actually only search the static table, missing
anything added into the dynamic table, which is pretty stupid.
The second issue was that nonIndexable header fields did extra
unnecessary work. This is because we asked the header table to search
for an exact match, but then disregarded whether or not one was found.
That meant a bunch of wasted computation.
Modifications:
- Fixed the table lookup to correctly search both dynamic and static
tables for partial matches.
- Correctly indicated that nonIndexable headers shouldn't care about
matching the header value.
Result:
Better handling of non-indexable headers.
* swift 5.1 docker setup
motivation: support swift 5.1
changes:
* add docker compose file for swift 5.1, will add CI job once merged
* update swiftformat version to 0.40.12
* use more standard dockerfile setup
* 16.04
Motivation:
Submodules can cause trouble with mirrored git setups because they can't
be easily mirrored through SwiftPM's mirror support.
Modification:
Remove the hpack-test-case submodule and add as files.
Result:
Easier to mirror.
Motivation:
HPACKHeaders are similar to HTTPHeaders but are missing a few useful
features:
- adding a sequence of headers to avoid reallocations, and
- being expressible as a dictionary literal.
Modifications:
- Add two `add(contentsOf:)` methods, one for key/value pairs, one for
key/value/indexing triplets.
- Add conformance to `ExpressibleByDictionaryLiteral`
Result:
HPACKHeaders is closer in feature parity to HTTPHeaders.
Motivation:
HTTP/2 is mostly just HTTP(/1) semantics with streams on a new wire
protocol. However, there are certain things that are legal in HTTP/1 but
which are illegal in HTTP/2.
Modification:
Accept more of those messages and transform them into their HTTP/2
equivalent.
Result:
- Easier to write HTTP/2 clients & servers in NIO.
- fixes#152
Motivation:
We should always recommend secure versions.
Modifcation:
Recommend `from: "1.5.0"`.
Result:
People will hopefully run more secure software.
Motivation:
We regressed 4 allocations in the security update
https://github.com/apple/swift-nio-http2/security/advisories/GHSA-jchv-x857-q8fq
. Four allocations are a great tradeoff for a number of security
vulnerabilities fixed but we need to raise the limits accordingly.
Modifications:
Raise the limits to the new limit so tests can pass again.
Result:
PRs can pass again and master should build again.
* Forbid excessive sending of empty DATA frames
Motivation:
One vector for DoS can be sending a large number of essentially "empty"
frames, such as empty DATA frames without END_STREAM set. We should
forbid peers from doing so excessively, but we want to tolerate
implementations that occasionally emit such a frame for buggy reasons.
Modifications:
- Added verification that too many empty DATA frames are not sent.
Result:
Better resistance to DoS attacks.
* Improved buffering in CompoundOutboundBuffer
Motivation:
In HTTP/2 it is possible for remote peers to submit work in a way that
cause the NIOHTTP2Handler to generate a substantial number of control
frames. If the peer is not consuming these frames, we can eventually run
out of memory and die, which is not exactly ideal.
It's hard for us to know how the buffering is going if we always submit
all frames directly to the Channel, so we need to pay attention to
whether the Channel is actually writable. If it isn't, rather than issue
further writes we need to delay those writes so we can keep track of how
big that buffer is getting. If the buffer gets too large we need a
circuit breaker to drop the connection, as we're clearly not able to get
work done.
This patch adds a new buffer for outbound control frames. This new
buffer is the last step in the buffering sequence, and the first to be
drained when a Channel becomes writable.
Additionally, enhancements need to be made to ensure that other buffers
behave correctly in the face of this new model. The
ConcurrentStreamsBuffer needs to be more aggressive about storing
HEADERS frames that cannot be emitted to the wire because it does not
tolerate emitting a HEADERS frame that cannot be immediately written to
the wire. Additionally, the buffers must not be polled when a Channel is
unwritable.
This is a large patch, but it does substantially change the buffering
logic, and protects NIO against a wide range of denial of service
attacks, while providing a clear and coherent defense surface.
Note that one thing this patch does not do is constrain the size of the
buffers in the ConcurrentStreamsBuffer. This is on purpose: the size of
this buffer is controlled entirely by user action. Users that do not
wish to buffer excessively in this buffer can avoid doing so simply by
respecting the peer's value of SETTINGS_MAX_CONCURRENT_STREAMS. As the
entire purpose of this buffer is to tolerate users that do not wish to
abide by this setting, it would be unreasonable to provide an upper
bound on the value used in this setting.
Modifications:
- Moved the various buffers into a directory.
- Built and implemented ControlFrameBuffer.
- Integrated ControlFrameBuffer into CompoundOutboundBuffer.
- Added awareness around channel writability to HTTP2Handler
- Enhanced ConcurrentStreamsBuffer to be writability-aware.
Result:
We'll have somewhere to put control frames.
* Cleanup API for merged security fixes.
Motivation:
After merging the security fixes we ended up with a slightly awkward
API: the argument names differed slightly for no good reason, and it
became impossible to override only one of the two security settings.
Modifications:
- Renamed `max` to `maximum`.
- Gave default values for the security settings.
Result:
Better user experience.
* Prevent DoS with large header lists.
Motivation:
There are two ways malicious peers could attempt to DoS a SwiftNIO
HTTP/2 implementation with header lists. The first would be to attempt
to send an enormous header list, ideally with an amplification factor.
This approach was possible because SwiftNIO never actually enforced the
value of the max header list size it advertised.
In principle the peer can still get a good amplification attack effect
by sending a long header list that contains zero-length headers. We may
as well close this door as well: zero length header field names are
unacceptable, and so we should forbid them.
Modifications:
- Added max header list enforcement.
- Forbade zero-length header field names.
Result:
Peers cannot DoS a SwiftNIO HTTP/2 implementation using large header
lists.
Motivation:
It's important to ensure that child channel users can observe the
writability state of a child channel in order to avoid ballooning data
in memory. Up until now we haven't supported writability notifications,
but we really should.
Modifications:
- Added a flow controller to manage writability.
- Managed data flow through promises.
- Lots of tests.
Result:
Child channels will provide a much better signal as to whether they are
writable.
Motivation:
Previously, the H2to1 codec would crash if for example a push promise
came by.
Modifications:
Instead of crashing, ignore the frames without equivalent.
Result:
Fewer crashes.
Motivation:
RFC 7540 is not particularly clear on whether the server is required to
send PUSH_PROMISE frames before or after the HEADERS frame, or whether
both are acceptable. We took a somewhat hard-line approach by asserting
that PUSH_PROMISE could only be sent after the server sent HEADERS, but
we've now caught at least one notable implementation in the wild doing
something different (nghttp2).
Given that there's no clear normative language pointing in either
direction, we should consider being a bit more lenient and allowing
both.
Modifications:
- Updated the stream state machine to allow pushes on a locally-idle
stream.
Result:
Servers can send PUSH_PROMISE before they have sent HEADERS.
motivation: prepare to run performance tests in ci
changes:
add performance-test docker-compose task
add script that can parse the performance test suite results and compare between two result-sets
add generic shell docker-compose task
Motivation:
Currently swift-nio-http2 is extremely naive with its use of
channelReadComplete calls in HTTP2StreamChannel, firing one
channelReadComplete call per frame read. In high frame load cases this
leads to a lot of excessive channelReadComplete traffic, which can cause
unnecessary time spent in flush calls.
We should try to minimise the amount of time we spend on this
bookkeeping and save the CPU cost.
Modifications:
- Store a linked-list of HTTP2StreamChannels that need to have
channelReadComplete fired on them.
- Fire channelReadComplete based on this linked list.
Result:
Moderate improvement in performance in high-throughput workloads.