Skip to content

[HTTP2] Prepare migration actions #456

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

Merged
merged 5 commits into from
Oct 13, 2021

Conversation

dnadoba
Copy link
Collaborator

@dnadoba dnadoba commented Oct 12, 2021

Motivation

During migration from HTTP/1.x to HTTP/2 (and vice versa) we may need to close and/or create connections. We previously did not allow any actions during migration. This PR lifts that limitation.

Changes

  • add new .migration case to Action to allow all possible combinations of actions that can happen during migration
  • add new ConnectionMigrationAction and EstablishedConnectionAction which can me combined to a "normal" ConnectionAction with the static .combined(_:_) method on ConnectionAction
  • use EstablishedAction in the private implementation to be able to combine it with a ConnectionMigrationAction
  • adjust tests

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Oct 12, 2021
http2State: HTTP2StateMachine,
newHTTP1Connection: Connection
) -> Action {
self.migrateFromHTTP1(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is very confusing: why is the outer function called migrateFromHTTP2 and the inner one called migrateFromHTTP1?

@@ -317,7 +351,7 @@ extension HTTPConnectionPool {
/// - Parameters:
/// - starting: starting HTTP connections from previous state machine
/// - backingOff: backing off HTTP connections from previous state machine
mutating func migrateConnections(
mutating func migrateFromHTTP2(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Its this name right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, good catch. It should be migrateFromHTTP1

let request: HTTPConnectionPool.StateMachine.RequestAction
let connection: EstablishedConnectionAction

var asStateMachineAction: HTTPConnectionPool.StateMachine.Action {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would normally be spelled as an initializer on the target type, which already exists. Do we need the helper?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It's just a bit more convenient but I will remove it.

case .closeConnection(let connection, let isShutdown):
return .migration(
createConnections: migrationAction.createConnections,
closeConnections: migrationAction.closeConnections + CollectionOfOne(connection),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't know if including CollectionOfOne is the most efficient way to achieve this append.

case migration(
createConnections: [(Connection.ID, EventLoop)],
closeConnections: [Connection],
isShutdown: StateMachine.ConnectionAction.IsShutdown
Copy link
Member

Choose a reason for hiding this comment

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

In which case would we run into this? I guess if we are in http/1 and are closing and a new http/2 connection comes up we should just close the new connection. No migrations should occur if we are in shutdown.

@dnadoba dnadoba force-pushed the dn-http-migration-action branch from 5908084 to d9a1bb6 Compare October 12, 2021 15:36
@dnadoba dnadoba requested a review from Lukasa October 12, 2021 15:52
@dnadoba dnadoba force-pushed the dn-http-migration-action branch from 89e35d0 to 17a1d0c Compare October 13, 2021 13:51
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

One minor style nit, otherwise this looks good.

if self.http2Connections!.isEmpty {
self.http2Connections = nil
}
if self.connections.isEmpty, self.http2Connections == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer && to , when we aren't doing conditional binding.

@dnadoba dnadoba merged commit c1a60d8 into swift-server:main Oct 13, 2021
@dnadoba dnadoba deleted the dn-http-migration-action branch October 13, 2021 15:11
@fabianfett fabianfett added this to the HTTP/2 support milestone Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants