Motivation:
In an earlier patch (1e68e51) we attempted to avoid emitting
WINDOW_UPDATE frames on streams that were already closed on their
inbound side. This was largely a reasonable fix, but we missed an
important area: END_STREAM in a sequence of frames.
This would be triggered if we received multiple DATA frames in a row,
where the last one contained END_STREAM but an earlier one triggered a
WINDOW_UPDATE. The stream state machine would have seen the END_STREAM
already and will forbid the WINDOW_UPDATE, but the stream channel won't
yet have seen it and will try to send it.
The fix is easy enough: look for END_STREAM earlier.
Modifications:
- Check for END_STREAM when the stream channel receives the frame, not
when it passes it into the pipeline.
Result:
Fewer spurious connection errors.
Motivation:
No point having conditional branches when the branch is always taken!
This doesn't hurt perf at all, the optimiser will trivially see through
this, but it does hurt readability. Relatedly, the single-letter
variable names here aren't great.
Modifications:
- Removed needless branch.
- Gave the variables better names.
Result:
Easier to understand code.
Co-authored-by: George Barnett <gbarnett@apple.com>
Motivation:
In some cases it's possible for a stream to emit a WINDOW_UPDATE frame
after receiving close from the network. This is unfortunate because in
the eyes of the `NIOHTTP2Handler` the stream no longer exists which
results in a connection-level error.
Modifications:
- Add a `close()` to the `InboundWindowManager`, no new frame sizes will
be produced if close has been called
- Use the above functionality when the stream is closing and when we
have seen end stream.
Result:
WINDOW_UPDATE frames are no longer emitted from the stream as a result
of delivering pending reads while closing.
Motivation:
HTTPHeaders and HPACKHeaders have very similar APIs, yet some of the
functionality of HTTPHeaders is missing from HPACKHeaders.
Modifications:
- Add `remove`, `replaceOrAdd`, `capacity` and `reserveCapacity` to
HPACKHeaders
Result:
- HPACKHeaders is closer in feature parity to HTTPHeaders
Motivation:
NIO's backpressure management systems rely on catching calls to read()
in the ChannelPipeline. This only works if your Channel implementation
actually makes those calls to read()! Sadly, HTTP2StreamChannel did not:
we instead just recursed directly into the Channel's read0().
While I'm here I also noticed that we produced a lot of
channelReadComplete messages in the pipeline unnecessarily. We did this
in the service of having a read "fast-path" where new frames would be
automatically delivered into the ChannelPipeline without being buffered
until channelReadComplete. This fast-path is probably inadvisable: I
don't think it provided a meaningful performance benefit anyway,
especially as the removal of that fast-path allowed us to suppress
unnecessary calls to channelReadComplete, and therefore unnecessary
calls to read() as well.
Modifications:
- Forced autoRead through the pipeline.
- Removed read() fast-path.
- Suppressed channelReadComplete if no frames were delivered.
- Updated tests.
Result:
Clearer I/O path, better auto-read handling.
Motivation:
We made a bunch of changes to resolve#214. We should add a test to
ensure we actually fixed the issue.
Modifications:
- Add a test verifying that we can write on streams in a different order
to the order in which we create them
- Add a corresponding test for frame-based streams verifying that the
first write on each stream must match the order in which the streams
were created
- Remove an unnecessary `throws` in the base HTTP2 to HTTP1 server codec
Result:
- No functionality change, just more tests.
Motivation:
We added HTTP2FramePayload-to-HTTP1 codecs as part of #214 but are yet
to deprecate their HTTP2-to-HTTP1 counterparts.
Modifications:
- Deprecate `HTTP2ToHTTP1ClientCodec`
- Deprecate `HTTP2ToHTTP1ServerCodec`
- Deprecate tests containing them
- (We already have tests for HTTP2FramePayload-to-HTTP1 codecs)
Result:
HTTP2-to-HTTP1 codecs are deprecated
Motivation:
As part of #214 we need to introduce new pipeline helpers to configure
the channel pipeline with the new handlers. This PR adds those helpers
and deprecates the old paths.
Modifications:
- Add pipeline helpers with the new streamID-less initializer
- Switch old pipeline helpers which provided codecs to use the new path
and codecs
- Duplicate SimpleClientServerTests and ConfiguringPipelineTests to add
frame payload based counterparts
- Deprecate older helpers and multiplexer init, delete tests which don't
hit deprecated paths (note: these still exist in the payload based
counterparts)
- Update Bench1Conn10kRequests to be payload based
Result:
- More 'FramePayload' based Tests
- Paths for creating an 'HTTP2Frame' based stream via
'HTTP2StreamMultiplexer' are now deprecated
Motivation:
As part of #214 we added a stream channel which deals with
`HTTP2Frame.FramePayload` as well as the relevant entry points in
`HTTP2StreamMultiplexer` to create these streams. We didn't add a
corresponding set of tests.
Modifications:
- Duplicate `HTTP2StreamMultiplexerTests`
- Refactor to make use of new stream creation function and new inbound
stream initializer
- Fix up a couple of bugs in `HTTP2StreamMultiplexer`:
- activate pending streams on `channelActive`
- deactivate pending streams on `channelInactive`
- change stream writability for pending streams on `channelWritabilityChanged`
- add implementation for `childChannelClosed(channelID:)`
Result:
- Tests for payload-based stream creation via `HTTP2StreamMultiplexer`
Motivation:
To lift the requirement that stream creation order must match the order
of the first write on those channels we added a payload-based stream
channel. We need a way for users to create these channels and initialze
these channels when they are inbound.
Modifications:
- Adds a `createStreamChannel` using a stream initialzer without a
stream ID
- Adds a new multiplexer `init` where the inbound stream initialzer does
not use stream IDs
- Adds an additional 'configure' to MultiplexerAbstractChannel
- Replaces the `init` in `MultiplexerAbstractChannel` with two `static func`s:
we can't switch on an optional stream ID since inbound streams always
have a stream ID; we need to be be able to explicitly support choosing
the type of channel we want.
- Minor refactoring in `HTTP2StreamChannel` to avoid duplication between the
`configure` functions
Result:
- The multiplexer can create payload based streams manually and when a
new stream is inbound.
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
We have many test utilities for `HTTP2Frame` which predominantly make
assertions about the payload. As part of the work done for #214 we'll
need to make these assertions on the payload rather than the frame.
Modifications:
- Refactor `HTTP2Frame` test utilities to pull the payload assertions
into separate assertions on `FramePayload`
- `HTTP2Frame` assertions call through to the payload assertions
Result:
We can make assertions about payloads.
Motivation:
As part of the work for #214 we need new codecs which transform
`HTTP2Frame.FramePayload` to and from the appropriate request and
response parts.
Modifications:
- Add `HTTP2FramePayloadToHTTP1ClientCodec`
- Add `HTTP2FramePayloadToHTTP1ServerCodec`
- Duplicate the HTTP2ToHTTP1CodecTests and update the relevant parts to
use payloads instead of frames.
- Add relevant test helpers.
- Note: the HTTP2 to HTTP1 (frame based) codecs haven't been deprecated:
doing so without warnings depends on #221.
Result:
- We can transform `HTTP2Frame.FramePayload` types to the relevant HTTP
client and server request and response types.
Motivation:
To test deprecated functionality without a bunch of warnings, tests must
be marked as deprecated. This also needs to be bubbled up to anywhere
calling that test, such as in the generated linux test manifests.
Our script to generate the manifests currently doesn't support this and
as part of #214 we'll need to deprecate a few things while keeping their
tests.
Modifications:
- Pull in the latest version of the `generate_linux_tests.rb` script
from SwiftNIO.
- Re-run the script, since it includes some formatting changes too.
Result:
- When we deprecate functionality, we can deprecate the tests without
the generate manifests emitting warnings.
Motivation:
As part of #214 we need to make `HTTP2StreamChannel` generic over the type
of message it expects to read and write. This allows us to define an
`HTTP2StreamChannel` which uses `HTTP2Frame.FramePayload` as its
currency type, rather than `HTTP2Frame`.
Modifications:
- Make `HTTP2StreamChannel` generic over `Message` which is constrained
by conformance to `HTTP2FrameConvertible` and
`HTTP2FramePayloadConvertible`
- `HTTP2StreamChannel` now expects to read in `Message`s (as opposed to
`HTTP2Frame`s) and have `Message`s written in to it.
- Added typealiases for frame and payload based stream channels.
- Added support for the payload based channel in
`MultiplexerAbstractChannel` (although one can't be created yet).
Result:
We can create payload based stream channels.
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
As part of the work in #214 we're going to need to update the
HTTP2ToHTTP1 codecs. These need to be replaced for the new channel
pipelines. The core of the logic will be identical in both cases, so
let's start by factoring that logic out into some nice standalone
objects that we can reuse.
Modifications:
- Pull out the base codecs into structures.
- Rewrite the main codecs in terms of these new structures.
Result:
Easier extension points.
Motivation:
As part of the work in #214, HTTP2StreamID will need to be able to
tolerate not knowing its stream ID. For now this is not a problem, but
we should think about everywhere we use the stream ID and make sure we
have a solid principle in mind. This lays the groundwork for future
enhancements.
Modifications:
- Update HTTP2StreamChannel to hold an optional stream ID.
- Update interface to HTTP2StreamMultiplexer to tolerate closing
channels without stream IDs (we'll need it later).
- Move the "get a new stream ID" functionality to a method on
HTTP2StreamMultiplexer.
- Validate we behave correctly with optional stream IDs in the channel.
Result:
We can tolerate stream IDs being not present.
Motivation:
As part of the work in #214 we need a way for the HTTP2StreamMultiplexer
to hold multiple kinds of channels. It would be best if doing so didn't
require substantial changes to HTTP2StreamMultiplexer, which is
difficult because right now it is tightly coupled to HTTP2StreamChannel.
There are a few ways we could do this. The most obvious option to most
Swift programmers would be to define a protocol that covers the surface
area we want to use, and then hold that. This works fairly well, but the
downside of it is that it will force all calls from
HTTP2StreamMultiplexer to become dynamically dispatched. These indirect
calls are optimisation boundaries and so provide some performance costs.
Another option would be to create a subclassing relationship. This is
ok, but it also forces us into the realm of dynamic dispatch on some of
these calls, and also provides general difficulty if we ever want to
provide a backing channel that isn't easily made into a subclass.
The remaining option is to provide an abstract object that uses an
`enum` to store the kinds of channel we know about, and jump through it.
This works really well for small numbers of channel types (1 and 2
channels being the best outcomes), as it introduces very few extra
branches which are highly predictable, as well as allowing direct
function calls. This is great: one predictable branch that cannot
possibly miss cache, followed by a direct function call. Joy of joys!
However, it would be best if we didn't tie ourselves into this
implementation strategy. After all, down the road we could well end up
with more kinds of channels, and at a certain point the cost of the
indirect function call becomes _lower_ than the cost of jumping through
the enumeration. For that reason, we should define an abstraction.
Enter: `MultiplexerAbstractChannel`. This concrete type defines the
interface that `HTTP2StreamMultiplexer` will use to interact with stream
channels. As it's internal, the abstraction is totally porous: Swift is
capable of optimising it away to nothing. This type is explicitly a
reference type, maintaining the semantic expected by
`HTTP2StreamMultiplexer`.
This provides a nice encapsulation over our abstraction.
`HTTP2StreamMultiplexer` never needs to know about how we abstract over
multiple channel types: the entire abstraction lives in a single, simple
file, and can easily be rewritten without difficulty.
Modifications:
- Define `MultiplexerAbstractChannel` and the interface expected by
`HTTP2StreamMultiplexer`.
- Define a `BaseChannel` `enum` that will be used to dispatch to
multiple `Channel` types.
- Rewrite `HTTP2StreamMultiplexer` to use this new abstraction.
Result:
A customisation point for new channels will exist.
Motivation:
As part of the work for #214 to enforce stream creation order we need to
remove the requirement that the data sent over the stream be aware of
its stream ID ahead of time. This requires that the channel transporting
the data provide the stream ID. As such we need a way to convert between
data with stream IDs and data without stream IDs.
Modifications:
- Add 'HTTP2FrameConvertible' protocol whose conforming types can make
an 'HTTP2Frame'.
- Add 'HTTP2FramePayloadConvertible' protocol whose conforming types can make
an 'HTTP2Frame.FramePayload'.
- Conform 'HTTP2Frame' and 'HTTP2Frame.FramePayload' to the above
protocols.
Result:
We have a protocol which an HTTP2 stream channel may be generic over.
Motivation:
Thread Sanitizer will find bugs which might be missed otherwise.
Modifications:
When running docker image for 1604/5.1 tests and h2spec are both compiled with --sanitize=thread
Result:
Tests are run with thread sanitizer turned on.
Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
Motivation:
Ruby on Xenial is too old for the cocoapods downloader which jazzy uses.
Modifications:
Change Dockerfile to not install Jazzy on xenial.
Result:
Dockerfile will build again, but bionic or later is required for docs.
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:
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