Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -3311,6 +3311,33 @@ def get_excluded(
return excluded


async def _wait_containers_started(compose: PodmanCompose, containers: list) -> None:
"""Poll until all containers have left the 'created' state.

For service_completed_successfully (--condition=stopped), podman wait may return
immediately if the container hasn't transitioned out of "created" state yet —
i.e. podman start was called but the container hasn't actually begun running.
We poll until all dependency containers have left the "created" state before
invoking podman wait, eliminating the race condition.
See: https://github.com/containers/podman-compose/issues/1330
"""
while True:
try:
statuses_raw = await compose.podman.output(
[], "inspect", ["--format={{.State.Status}}"] + containers
)
statuses = statuses_raw.decode().split()
if all(s != "created" for s in statuses if s):
break
except subprocess.CalledProcessError:
pass
log.debug(
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should make this log message appear at most once a second.

"Waiting for dependency containers to leave 'created' state: %s",
', '.join(containers),
)
await asyncio.sleep(0.05)


async def check_dep_conditions(compose: PodmanCompose, deps: set) -> None:
"""Enforce that all specified conditions in deps are met"""
if not deps:
Expand Down Expand Up @@ -3338,6 +3365,9 @@ async def check_dep_conditions(compose: PodmanCompose, deps: set) -> None:
deps_cd.extend(compose.container_names_by_service[d.name])

if deps_cd:
if condition == ServiceDependencyCondition.STOPPED:
await _wait_containers_started(compose, deps_cd)

# podman wait will return always with a rc -1.
while True:
try:
Expand Down