Skip to content

V3: Fixed an issue where IAmazonS3.EnsureBucketExists(Async) was throwing an exception if S3 bucket already exists in the executing account. #3826

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

Open
wants to merge 1 commit into
base: aws-sdk-net-v3.7-development
Choose a base branch
from

Conversation

ashishdhingra
Copy link
Contributor

@ashishdhingra ashishdhingra commented May 19, 2025

Description

Fixed an issue where IAmazonS3.EnsureBucketExists(Async) was throwing an exception if S3 bucket already exists in the executing account.

Kindly note below for 1st version:

  • Refer Using the handle method to filter inner exceptions on how to handle exceptions when using async Task based version.
  • After handling exception for async version, we return Task.FromResult(0). This is because:
    • If we return the original Task object, it re-throws exception in the calling awaited thread.
    • Task.CompletedTask doesn't exist in NET45 target.

Motivation and Context

Issue #3807

Testing

  • Added integration test.
  • Dry-run DRY_RUN-32d10e46-52d0-421f-9bc7-943cdd6348cd completed successfully.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

@@ -145,7 +145,21 @@ Task ICoreAmazonS3.MakeObjectPublicAsync(string bucket, string objectKey, bool e

Task ICoreAmazonS3.EnsureBucketExistsAsync(string bucketName)
{
return this.PutBucketAsync(bucketName);
Task task = this.PutBucketAsync(bucketName);
Copy link
Member

Choose a reason for hiding this comment

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

You should just use the async/await something like.

async Task ICoreAmazonS3.EnsureBucketExistsAsync(string bucketName)
{
   try
   {
        await this.PutBucketAsync(bucketName);
   }
   catch(BucketAlreadyOwnedByYouException)
   {
   }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The exception in this.PutBucketAsync(bucketName) is thrown in another thread and based on my testing, catch block wouldn't handle it. Hence, I needed to resort to exception handling based on Microsoft's documentation. The only difference I see in your proposed code is addition of async to method signature. Let me give it a try.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. It's working. Starting dry-run.

@peterrsongg peterrsongg requested a review from afroz429 May 20, 2025 17:26
… an exception if S3 bucket already exists in the executing account.
@ashishdhingra ashishdhingra force-pushed the user/ashdhin/V3-DOTNET-8131-EnsureBucketExistsAsync branch from dd96bd0 to 0d84f95 Compare May 20, 2025 18:54
@ashishdhingra ashishdhingra requested a review from normj May 20, 2025 18: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