Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic helpers for HTTP/2 async pipelines #401

Merged
merged 18 commits into from Jul 3, 2023

Conversation

rnro
Copy link
Contributor

@rnro rnro commented Jun 26, 2023

Expose (as spi) generic helpers for HTTP/2 async pipelines

Motivation:

This PR is the first step in exposing APIs which surface HTTP/2 connections/streams using structured concurrency. This PR exposes the most abstract spelling of this concept, assuming no particular types/forms for the types involved in the stream channel types.

Modifications:

  • Define types and methods for storing generic types which wrap Channels corresponding to inbound HTTP/2 streams in an async sequence.
  • Store a generic streamInitializer on the common inbound initializer which is used to initialize inbound streams before yielding them to the continuation of streams.
  • Expose pipeline configuration functions which assume HTTP/2 but nothing else about sream channel types.
  • Provide internal functions for creating streams without configuring them. Configuring leads to activation so it can be helpful to allow that step to be performed manually once any provided initialization closures have beenn executed.

Result:

Adopters of the new SPI should be able to create outbound and deal with inbound HTTP/2 stream channels using async streams.

Outside of SPI there should be no changes.

rnro added 4 commits June 23, 2023 16:25
Motivation:

In preparation for exposing APIs which surface HTTP/2 connections and
streams using structured concurrency this PR introduces a store for
inbound HTTP/2 streams.

Modifications:

Define types and methods for storing generic types which wrap `Channels`
corresponding to inbound HTTP/2 streams in an async sequence.

Result:

The new types are not yet exposed, this work introduces part of the
framework for future functionality.
Motivation:

This PR is the first step in exposing APIs which surface HTTP/2 connections and
streams using structured concurrency. This PR exposes the most abstract
spelling of this concept, assuming no particular types/forms for the
types involved in the stream channel types.

Modifications:

* Store a generic `streamInitializer` on the common inbound initializer
  which is used to initialize inbound streams before yielding them to
the continuation of streams.
* Expose pipeline configuration functions which assume HTTP/2 but
  nothing else about sream channel types.

Result:

Adopters of the new SPI should be able to create outbound and deal with
inbound HTTP/2 stream channels using async streams.

Outside of SPI there should be no changes.
* Finish stream channel sequence continuation
* Provide internal functions for creating streams without configuring
  them. Configuring leads to activation so it can be helpful to allow
that step to be performed manually once any provided initialization
closures have beenn executed.
@glbrntt glbrntt self-requested a review June 26, 2023 10:02
Copy link
Contributor

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start! Left some inline comments here and there

Package.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Show resolved Hide resolved
Package.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2StreamChannel.swift Outdated Show resolved Hide resolved
@rnro rnro force-pushed the async_connection_channel branch from 6fea265 to e9c7f8e Compare June 27, 2023 14:52
@rnro rnro requested review from glbrntt and FranzBusch June 27, 2023 14:53
@rnro rnro force-pushed the async_connection_channel branch from 737f00c to 3a65355 Compare June 28, 2023 08:24
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Tests/NIOHTTP2Tests/TestUtilities.swift Outdated Show resolved Hide resolved
Tests/NIOHTTP2Tests/TestUtilities.swift Show resolved Hide resolved
Tests/NIOHTTP2Tests/TestUtilities.swift Outdated Show resolved Hide resolved
Tests/NIOHTTP2Tests/TestUtilities.swift Outdated Show resolved Hide resolved
Tests/NIOHTTP2Tests/TestUtilities.swift Outdated Show resolved Hide resolved
Copy link
Contributor

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks super good already and I think we are getting quite close here!

Sources/NIOHTTP2/HTTP2ChannelHandler.swift Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2CommonInboundStreamMultiplexer.swift Outdated Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2PipelineHelpers.swift Show resolved Hide resolved
Sources/NIOHTTP2/HTTP2StreamChannel.swift Show resolved Hide resolved
Comment on lines 101 to 102
let serverRecorder = InboundFramePayloadRecorder()
serverRecorderContinuation.yield(serverRecorder)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is safe. The InboundFramePayloadRecorder is probably not Sendable. What I meant with my previous comment was actually passing the continuation into this recorder so that the recorder is yielding whatever it records to it. (We might want to create a complete new type for this instead of botching the InboundFramePayloadRecorder)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I realized afterwards that this is probably not what you meant however I think it works as a convenient way to get the recorders out of the initializers and indicate when they're 'done'. I have made InboundFramePayloadRecorder Sendable to make it safe.

@rnro rnro requested review from glbrntt and FranzBusch June 29, 2023 13:55
@rnro rnro requested a review from glbrntt June 30, 2023 08:19
@rnro rnro force-pushed the async_connection_channel branch from c31c408 to 34fe176 Compare June 30, 2023 11:08
@rnro rnro force-pushed the async_connection_channel branch from 34fe176 to 43676e8 Compare June 30, 2023 11:25
Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of nits, but very nearly there!

Copy link
Contributor

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rnro rnro merged commit 83c04db into apple:main Jul 3, 2023
8 checks passed
@rnro rnro deleted the async_connection_channel branch July 3, 2023 10:19
@Lukasa Lukasa added the patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1) label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch-version-bump-only For PRs that when merged will only cause a bump of the patch version, ie. 1.0.x -> 1.0.(x+1)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants