Skip to content

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

Merged
merged 5 commits into from
Jul 18, 2025

Conversation

sichanyoo
Copy link
Contributor

@sichanyoo sichanyoo commented Jul 9, 2025

Companion PR:

Issue #

3359

Description of changes

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.

hashResult = cachedChecksum
} else {
hashResult = try checksum.digest().toBase64String()
context.set(key: AttributeKey<String>(name: "ChunkedStreamCachedChecksum"), value: hashResult)
Copy link
Contributor

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

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.

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)
Copy link
Contributor

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?

@jbelkins jbelkins self-requested a review July 17, 2025 19:38
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.

Tested in Xcode Instruments for memory leakage. Confirmed that there are none, approving.

@sichanyoo sichanyoo merged commit ca83732 into main Jul 18, 2025
53 of 57 checks passed
@sichanyoo sichanyoo deleted the feat/reuse-checksum-in-retries branch July 18, 2025 00:14
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