Skip to content

Commit d2a6153

Browse files
committed
Handle builder creation race condition with an exception
1 parent 3ef9e2c commit d2a6153

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

scripts/release/build_images.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def ecr_login_boto3(region: str, account_id: str):
4343
def ensure_buildx_builder(builder_name: str = DEFAULT_BUILDER_NAME) -> str:
4444
"""
4545
Ensures a Docker Buildx builder exists for multi-platform builds.
46+
This function is safe for concurrent execution across multiple processes.
4647
4748
:param builder_name: Name for the buildx builder
4849
:return: The builder name that was created or reused
@@ -66,6 +67,13 @@ def ensure_buildx_builder(builder_name: str = DEFAULT_BUILDER_NAME) -> str:
6667
)
6768
logger.info(f"Created new buildx builder: {builder_name}")
6869
except DockerException as e:
70+
# Check if this is a race condition (another process created the builder)
71+
if hasattr(e, 'stderr') and 'existing instance for' in str(e.stderr):
72+
logger.info(f"Builder '{builder_name}' was created by another process – using it.")
73+
docker.buildx.use(builder_name)
74+
return builder_name
75+
76+
# Otherwise, it's a real error
6977
logger.error(f"Failed to create buildx builder: {e}")
7078
raise
7179

0 commit comments

Comments
 (0)