-
Notifications
You must be signed in to change notification settings - Fork 33
feat: Checksum reuse between retries in chunked streaming requests #946
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
Conversation
hashResult = cachedChecksum | ||
} else { | ||
hashResult = try checksum.digest().toBase64String() | ||
context.set(key: AttributeKey<String>(name: "ChunkedStreamCachedChecksum"), value: hashResult) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we avoid directly typing out "ChunkedStreamCachedChecksum"
and either use a variable or add it where the other AttributeKeys live
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment on storing Context in signing properties.
@@ -57,6 +57,11 @@ extension SignerMiddleware: ApplySigner { | |||
updatedSigningProperties.set(key: AttributeKey(name: "SignedBodyValue"), value: bodyValue) | |||
} | |||
|
|||
if case .stream(let stream) = request.body, stream.isEligibleForChunkedStreaming { | |||
// Pass in context object via signing properties to reuse final checksum value in chunked streaming. | |||
updatedSigningProperties.set(key: AttributeKey(name: "Context"), value: attributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful here... if we put Context into signing properties then we put those signing properties into Context, a reference cycle is formed and a memory leak will occur.
Maybe better to copy the specific things we need from Context into signingProperties?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in Xcode Instruments for memory leakage. Confirmed that there are none, approving.
Companion PR:
Issue #
3359
Description of changes
Scope
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.