Skip to content

fix(storage): sign_with is Send#4399

Merged
dbolduc merged 2 commits intogoogleapis:mainfrom
msdrigg:patch-1
Jan 26, 2026
Merged

fix(storage): sign_with is Send#4399
dbolduc merged 2 commits intogoogleapis:mainfrom
msdrigg:patch-1

Conversation

@msdrigg
Copy link
Copy Markdown
Contributor

@msdrigg msdrigg commented Jan 26, 2026

This PR updates signed_url.rs to ensure that when canonical_query is created (using a Serializer which is non-send), we drop the Serializer at that point so it doesn't remain alive until the end of the scope.

Currently even though the canonical_query variable is shadowed, rust does not automatically drop the shadowed variable until the end of scope, and .finish() only takes an &mut Serializer. So the original non-send canonical_query lives for the whole scope across an await point and therefore makes sign_with non-send.

… `async fn sign_with` is send

Update signed_url.rs to ensure that when canonical_query is created (using a Serializer which is non-send), we drop the Serializer at that point so it doesn't remain alive until the end of the scope.

Currently even though the canonical_query variable is shadowed, rust does not automatically drop the shadowed variable until the end of scope, and `.finish()` only takes an `&mut Serializer`. So the original non-send `canonical_query` lives for the whole scope across an await point and therefore makes `sign_with` non-send.
@msdrigg msdrigg requested a review from a team January 26, 2026 17:18
@google-cla
Copy link
Copy Markdown

google-cla bot commented Jan 26, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@dbolduc
Copy link
Copy Markdown
Member

dbolduc commented Jan 26, 2026

/gcbrun

@msdrigg msdrigg changed the title Localize canonical query construction so sign_with is send Reduce scope of canonical query construction so sign_with is send Jan 26, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.94%. Comparing base (a4b377e) to head (435cdf6).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4399      +/-   ##
==========================================
+ Coverage   94.93%   94.94%   +0.01%     
==========================================
  Files         191      191              
  Lines        7262     7261       -1     
==========================================
  Hits         6894     6894              
+ Misses        368      367       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dbolduc dbolduc changed the title Reduce scope of canonical query construction so sign_with is send fix(storage): sign_with is Send Jan 26, 2026
dbolduc
dbolduc previously approved these changes Jan 26, 2026
Copy link
Copy Markdown
Member

@dbolduc dbolduc left a comment

Choose a reason for hiding this comment

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

Hey, you are totally right. Good catch, and thanks for the fix!

Our linter is unhappy with the formatting though. We need to fix that before merging.

Also, optionally, can you add a unit test so that this doesn't happen again? I was thinking something like the following (which I tested locally):

    fn assert_send<T: Send>(_t: &T) {}

    #[tokio::test]
    async fn sign_with_is_send() -> TestResult {
        let mut mock = MockSigner::new();
        mock.expect_client_email()
            .return_once(|| Ok("test@example.com".to_string()));
        mock.expect_sign()
            .return_once(|_content| Err(SigningError::from_msg("test".to_string())));

        let signer = Signer::from(mock);
        let fut = SignedUrlBuilder::for_object("projects/_/buckets/b", "o").sign_with(&signer);

        assert_send(&fut);

        Ok(())
    }

Thanks!

@msdrigg
Copy link
Copy Markdown
Contributor Author

msdrigg commented Jan 26, 2026

Give me a minute on the test, just fixed the suggested lint issue

dbolduc
dbolduc previously approved these changes Jan 26, 2026
@dbolduc
Copy link
Copy Markdown
Member

dbolduc commented Jan 26, 2026

Give me a minute on the test, just fixed the suggested lint issue

No worries on the test. I can always add it in a follow up PR. Your PR is good to go.

Also thanks for doing the CLA business

@dbolduc
Copy link
Copy Markdown
Member

dbolduc commented Jan 26, 2026

/gcbrun

Co-authored-by: Darren Bolduc <dbolduc@google.com>
@msdrigg
Copy link
Copy Markdown
Contributor Author

msdrigg commented Jan 26, 2026

Sorry just saw your comment here -- added the test and ensured it passed, and ran cargo fmt again on the whole file

@dbolduc
Copy link
Copy Markdown
Member

dbolduc commented Jan 26, 2026

Sorry just saw your comment here -- added the test and ensured it passed, and ran cargo fmt again on the whole file

Even better. Thanks!

@dbolduc
Copy link
Copy Markdown
Member

dbolduc commented Jan 26, 2026

/gcbrun

@alvarowolfx alvarowolfx self-requested a review January 26, 2026 18:13
@msdrigg
Copy link
Copy Markdown
Contributor Author

msdrigg commented Jan 26, 2026

Let me know if you need anything else like rebase etc.

@dbolduc dbolduc enabled auto-merge (squash) January 26, 2026 18:21
@dbolduc dbolduc merged commit 6568506 into googleapis:main Jan 26, 2026
30 of 31 checks passed
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