Skip to content

All internal connection flow should be executed when shutting down #268

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
Jun 22, 2020

Conversation

artemredkin
Copy link
Collaborator

All internal connection flow should be executed when shutting down.

Motivation:
When we shut the client down, we expect the provider to finish all its tasks, if there are some, and then delete itself and succeed the close promise. Currently, if connection is created unsuccessfully, or available connection is closed/times out before we close it as part of shutdown, those connection will not trigger correct flow.

Modifications:

  1. connectFailed now triggers correct flow when client is .closed
  2. timeout now triggers correct flow when client is .closed
  3. removeClose now triggers correct flow when client is .closed
  4. offer is refactored
  5. Added 4 new tests, that specifically test described scenarios

Result:
Closes #263
Closes #260

@artemredkin artemredkin requested a review from weissi June 19, 2020 13:51
@artemredkin artemredkin added this to the 1.2.0 milestone Jun 19, 2020
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.

Seems reasonable to me.

let waiter = HTTP1ConnectionProvider.Waiter(promise: connectionPromise, setupComplete: setupPromise.futureResult, preference: .indifferent)
var action = state.acquire(waiter: waiter)

switch action {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: you can write this a bit shorter as

guard case .create = action else {
    XCTFail("unexpected action \(action)")
    return
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍


action = state.offer(connection: connection)
switch action {
case .closeAnd(_, let next):
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't this

guard case .closeAnd(_, .closeProvider) = action else {
    XCTFail("unexpected action \(action)")
    return
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

let waiter = HTTP1ConnectionProvider.Waiter(promise: connectionPromise, setupComplete: setupPromise.futureResult, preference: .indifferent)
var action = state.acquire(waiter: waiter)

switch action {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this could be a guard too I think

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

}

action = state.connectFailed()
switch action {
Copy link
Contributor

Choose a reason for hiding this comment

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

this too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

👍

@artemredkin artemredkin requested a review from weissi June 22, 2020 15:08
Copy link
Contributor

@weissi weissi left a comment

Choose a reason for hiding this comment

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

Awesome, LGTM!

@artemredkin artemredkin merged commit aec3fee into swift-server:master Jun 22, 2020
@artemredkin artemredkin deleted the fix_shutdown_crash branch June 22, 2020 15:12
artemredkin added a commit to artemredkin/async-http-client that referenced this pull request Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants