Skip to content

Commit d298487

Browse files
Handle BucketAlreadyOwnedByYou race condition in S3 bucket initialization
The default S3 bucket name is deterministic per account+region, so concurrent cluster creation calls (e.g. parallel integration tests) can race: multiple callers get a 404 from head_bucket, then all attempt create_bucket. The first succeeds; the rest fail with BucketAlreadyOwnedByYou, which was previously unhandled and surfaced as "Unable to initialize s3 bucket." Treat BucketAlreadyOwnedByYou as a success condition since it confirms the bucket exists and is owned by the caller, which is the desired end state. Log at info level and proceed normally.
1 parent 6870bc8 commit d298487

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
CHANGELOG
22
=========
33

4+
3.16.0
5+
------
6+
7+
**BUG FIXES**
8+
- Fix sporadic S3 bucket creation failure when multiple create-cluster commands are running simultaneously in the same region.
9+
410
3.15.0
511
------
612

cli/src/pcluster/models/s3_bucket.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,11 @@ def _create_bucket(cls, bucket: S3Bucket, e: AWSClientError):
478478
try:
479479
bucket.create_bucket()
480480
except AWSClientError as error:
481-
LOGGER.error("Unable to create S3 bucket %s.", bucket.name)
482-
raise error
481+
if error.error_code == "BucketAlreadyOwnedByYou":
482+
LOGGER.info("S3 bucket %s was created shortly before by another process. Proceeding.", bucket.name)
483+
else:
484+
LOGGER.error("Unable to create S3 bucket %s.", bucket.name)
485+
raise error
483486
else:
484487
LOGGER.error("Unable to check S3 bucket %s existence.", bucket.name)
485488
raise e

0 commit comments

Comments
 (0)