Skip to content

Fix HTTP1 to HTTP2 migration while shutdown is in progress #530

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 4 commits into from
Dec 17, 2021

Conversation

dnadoba
Copy link
Collaborator

@dnadoba dnadoba commented Dec 17, 2021

Motivation

Calling HTTPClient.shutdown() may never return if connections are still starting and one new established connection results in a state migration (i.e. from HTTP1 to HTTP2 or vice versa). We forgot to migrate the shutdown state. This could result in a large delay until .shutdown() returns because we wait until connections are closed because of idle timeout. Worse, it could also never return if more requests are queued because the connections would not be idle and therefore not close itself.

Changes

  • Mirgrate shutdown state too
  • add tests for this specific case

@dnadoba dnadoba requested a review from fabianfett December 17, 2021 09:06
@dnadoba dnadoba added the 🔨 semver/patch No public API change. label Dec 17, 2021
### Motivation
Calling `HTTPClient.shutdown()` may never return if connections are still starting and one new established connection results in a state migration (i.e. from HTTP1 to HTTP2 or vice versa). We forgot to migrate the shutdown state. This could result in a large dealy until `.shutdown()` returns because we wait until connections are closed because of idle timeout. Worse, it could also never return if more requests are queued because the connections would not be idle and therefore not close itself.
###Changes
- Mirgrate shutdown state too
- add tests for this specific case
@dnadoba dnadoba force-pushed the dn-fix-migration-during-shutdown branch from 7604763 to 54a3a68 Compare December 17, 2021 10:11
@@ -670,6 +673,89 @@ class HTTPConnectionPool_HTTP2StateMachineTests: XCTestCase {
XCTAssertTrue(queuer.isEmpty)
}

func testMigrationFromHTTP1ToHTTP2WhileShuttingDown() {
Copy link
Member

Choose a reason for hiding this comment

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

I think this test case is a little to complex... let's just focus on the thing that we actually observed.

  1. run request -> opens new connection (expect h1)
  2. shutdown pool -> queued request shall be cancelled
  3. connection creation is done as h2 -> connection shall be closed immediately and shutdown is done.

then we should also have this vica versa.

  1. run request -> opens new connection
  2. connection creation is done as h2 -> schedule request on h2 connection
  3. connection is done with the single request
  4. idle timeout closes h2 connection
  5. new request comes in. we create a new connection (expect h2)
  6. shutdown pool -> cancel queued request
  7. connection creation is done as h1 -> connection shall be closed immediately and shutdown is done.

Copy link
Member

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

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

Looks awesome! Thanks!

@dnadoba dnadoba force-pushed the dn-fix-migration-during-shutdown branch from 6796ea0 to 8a7db19 Compare December 17, 2021 13:12
@dnadoba dnadoba merged commit e4b11eb into swift-server:main Dec 17, 2021
@dnadoba dnadoba deleted the dn-fix-migration-during-shutdown branch December 17, 2021 13:44
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.

2 participants