Skip to content

fix: Fix CRT HTTP client continuation bug #711

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 15 commits into from
May 22, 2024

Conversation

sichanyoo
Copy link
Contributor

@sichanyoo sichanyoo commented May 3, 2024

Issue #

awslabs/aws-sdk-swift#1474

Description of changes

Uses a class that wraps the continuation to ensure the StreamContinuation that gets passed around in CRTClientEngine.swift gets resumed exactly once.

*Confirmed with Waqar that the callback functions do not get called concurrently in the underlying aws-crt-swift client engine, hence no need for special handling for the flag to make it concurrency safe.

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sichanyoo sichanyoo changed the title fix: Fix continuation bug by using DispatchQueue and boolean flag. fix: Make CRT HTTP client default for macOS & fix continuation bug May 3, 2024
Copy link
Contributor

@dayaffe dayaffe left a comment

Choose a reason for hiding this comment

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

Two small suggestions! Great work on fixing this

@sichanyoo sichanyoo requested a review from dayaffe May 3, 2024 23:17
@@ -361,4 +410,36 @@ public class CRTClientEngine: HTTPClient {
response.body = .stream(stream)
return requestOptions
}

class ContinuationFlag {
private var continuationResumed = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than have a continuationResumed flag, why not have this class just store the continuation? Once the continuation is resumed, set the reference to it to nil.

That gives you the same indication as the flag, and also protects against calling the continuation twice (be eliminating the reference to it.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good point; changed as suggested.

continuation: continuation,
http2ManualDataWrites: true
)
Task {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this Task? It contains some code that doesn't appear to be async, then creates yet another async task from inside it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I must've forgot to clean it up; deleted as pointed out 👍

@@ -80,7 +80,7 @@ public extension DefaultSDKRuntimeConfiguration {
static func makeClient(
httpClientConfiguration: HttpClientConfiguration = defaultHttpClientConfiguration
) -> HTTPClient {
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS) || os(macOS)
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's split this out to a separate PR since it is unrelated to the fix below and these are both significant changes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok 👍

@sichanyoo sichanyoo changed the title fix: Make CRT HTTP client default for macOS & fix continuation bug fix: Fix CRT HTTP client continuation bug May 20, 2024
@sichanyoo sichanyoo requested a review from jbelkins May 21, 2024 16:09
Copy link
Contributor

@jbelkins jbelkins left a comment

Choose a reason for hiding this comment

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

Just small stuff this time

class ContinuationWrapper {
private var continuation: StreamContinuation?

public init(_ continuation: StreamContinuation? = nil) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Since you will always create this type with a continuation that is non-nil, make this param required & eliminate the default nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed as suggested

}
}
}
}

/// Creates a `HTTPRequestOptions` object that can be used to make a HTTP request
/// - Parameters:
/// - continuationFlag: The actor that wraps the boolean flag used to track continuation resume status
Copy link
Contributor

Choose a reason for hiding this comment

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

update this doc comment to match current method sig

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed as suggested

@sichanyoo sichanyoo requested a review from jbelkins May 22, 2024 16:55
@sichanyoo sichanyoo requested review from dayaffe and removed request for dayaffe May 22, 2024 17:20
@sichanyoo sichanyoo merged commit f29e57c into main May 22, 2024
17 checks passed
@sichanyoo sichanyoo deleted the fix/crt-http-client-continuation branch May 22, 2024 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants