Files
floci/src/main/java/io/github/hectorvent
Kenshin Okinaka 44da9da6bb fix(docker): retry transient registry failures during image pull (#1117)
ImageCacheService.ensureImageExists surfaced docker-java's pull
exceptions straight to its caller on the first failure. When the
underlying registry returned a transient 5xx — most notably ECR
Public's / Docker Hub's "toomanyrequests" rate limit — this caused
the surrounding operation to fail outright even though a retry a
moment later would succeed. In CodeBuild's case it manifested as
build status FAULT (CodeBuildRunner catches the exception and sets
status=FAULT + buildComplete=true), showing up as flakes in the
sdk-test-java CI job on PRs that don't touch CodeBuild at all.

- Add runWithRetry(imageUri, maxAttempts, initialBackoffMs, attempt)
  static helper that retries transient pull failures up to
  MAX_PULL_ATTEMPTS=3 times with exponential backoff starting at
  INITIAL_BACKOFF_MS=500ms (500ms -> 1s -> 2s). The throwable is
  passed to LOG.warnv(e, ...) so the cause survives in the log
  stream, matching the Floci-wide pattern (SmtpRelay,
  CognitoAuthFlowHandler, etc.).
- A failure is treated as transient when either:
  (a) the docker daemon throws InternalServerErrorException directly
      (HTTP 500, sync path), or
  (b) PullImageResultCallback.awaitCompletion rewraps the same
      daemon error as DockerClientException whose message starts
      with "Could not pull image: " (async-callback path; same root
      cause, different exception class). Both forms have been
      observed against ECR Public and Docker Hub in CI.
- isTransientPullFailure(e) helper centralizes the classification.
  Permanent failures (auth, missing image, malformed request, or
  any other DockerClientException not coming from the pull wrapper)
  keep surfacing their original docker-java exception subclass on
  the first attempt and are not retried.
- Wire ensureImageExists's existing pull invocation through the
  retry helper. The synchronized-once and isLocalImagePresent
  fast-path semantics are unchanged.
- New ImageCacheServiceTest covers nine cases against the static
  helper (no DockerClient mocking needed): first-attempt success,
  retry-then-succeed (sync InternalServerErrorException),
  max-attempts-exhausted-rethrows, no-retry-on-NotFoundException,
  no-retry-on-UnauthorizedException, no-retry-on-generic-
  DockerException, retry-then-succeed on the pull-wrapper
  DockerClientException, no-retry on an unrelated
  DockerClientException (container start failure), and
  InterruptedException propagated as-is.

Out of scope: NeptuneContainerManager and other container managers
that call dockerClient.pullImageCmd directly (bypassing
ImageCacheService) still hit the same rate-limit path without
retries. Routing those through ImageCacheService is a separate
refactor.
2026-06-02 00:33:24 -05:00
..