Skip to content

registry: fix TOCTOU race condition in local registry initialization - #143

Merged
alicefr merged 1 commit into
bootc-dev:mainfrom
HarshwardhanPatil07:fix-registry-race-condition
Sep 21, 2026
Merged

alicefr merged 1 commit into
bootc-dev:mainfrom
HarshwardhanPatil07:fix-registry-race-condition

Conversation

@HarshwardhanPatil07

@HarshwardhanPatil07 HarshwardhanPatil07 commented Sep 21, 2026

Copy link
Copy Markdown
Member

In parallel integration test runs, multiple cluster start operations
concurrently ensure the shared singleton bink-registry container.
When a worker invokes ensureExistingContainer (either because ContainerExists
returned true or following a concurrent creation conflict), calling
ContainerStatus immediately can fail with a 404 "no such container"
error while Podman's internal container state is still settling. Additionally,
concurrent ContainerStart invocations can race if another worker transitions
the container to running mid-flight.

Fix this by:

  1. Adding a bounded retry loop to ContainerStatus in ensureExistingContainer
    to allow transient unready/inspection states to settle.
  2. Checking if the container is already running before failing if
    ContainerStart returns an error during concurrent startup.
  3. Pre-starting the shared registry once in SynchronizedBeforeSuite on
    Node 1 before parallel integration test workers run.

Assisted-by: AI

@HarshwardhanPatil07
HarshwardhanPatil07 force-pushed the fix-registry-race-condition branch from 81a0b47 to c0cd0bc Compare September 21, 2026 06:13
@HarshwardhanPatil07

Copy link
Copy Markdown
Member Author

saw tests failing in #142

Comment thread internal/registry/registry.go Outdated
status, err := m.podman.ContainerStatus(ctx, name)
var status string
var err error
for attempts := 0; attempts < 10; attempts++ {

@alicefr alicefr Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this try 10 times if the container hasn't been started?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yep, reduced it to 3 retries. Thank you!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok, this isn't the default path so we don't always retry at every registry creation

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we add the retries logic in the function recoverFromConcurrentCreate? This is already done for exactly catch that case

@HarshwardhanPatil07
HarshwardhanPatil07 force-pushed the fix-registry-race-condition branch from c0cd0bc to d87fb5a Compare September 21, 2026 06:58
In parallel integration test runs, multiple cluster start operations
concurrently ensure the shared singleton bink-registry container.
When two workers attempt to create the container at the same time, the
losing worker encounters an 'already in use' conflict and enters
recoverFromConcurrentCreate. Calling ensureExistingContainer immediately
can fail with a 404 "no such container" error while Podman's internal
container record is still settling. Additionally, concurrent ContainerStart
invocations can race if another worker transitions the container to
running mid-flight.

Fix this by:
1. Retrying ensure in recoverFromConcurrentCreate with backoff when
   concurrent creation is detected, giving the winning worker time to
   finalize container creation.
2. Checking if the container is already running before failing if
   ContainerStart returns an error during concurrent startup.
3. Pre-starting the shared registry once in SynchronizedBeforeSuite on
   Node 1 before parallel integration test workers run.

Assisted-by: AI
Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
@HarshwardhanPatil07
HarshwardhanPatil07 force-pushed the fix-registry-race-condition branch from d87fb5a to e5a8024 Compare September 21, 2026 07:20
@alicefr
alicefr merged commit 9807f6b into bootc-dev:main Sep 21, 2026
13 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.

2 participants