Skip to content

Remove the Docker containers of runs that were stopped or killed - #418

Merged
schlessera merged 1 commit into
mainfrom
feature/docker-cleanup
Nov 2, 2026
Merged

schlessera merged 1 commit into
mainfrom
feature/docker-cleanup

Conversation

@schlessera

Copy link
Copy Markdown
Member

Follow-up to #408.

A run in Docker containers removes them in shutdown functions, which PHP skips when a signal ends the process. Stopping a run with Ctrl+C or timeout, or killing it, left its containers running: the database containers are started detached, so nothing else removes them.

Signals

When the pcntl extension is available, SIGINT, SIGTERM and SIGHUP end the run through exit() (with 130, 143 and 129), so the shutdown functions remove the containers. The run with scenarios selected by path now waits for its container in PHP instead of in passthru(), so the handlers run there as well. Without pcntl, nothing changes.

Leftovers of killed runs

Every container gets a wp-cli-tests.owner=<host>:<pid> label. Before starting containers, a run removes the labelled containers of this host whose process no longer exists. That covers SIGKILL, crashes and reboots, and it is safe:

  • Containers of a run that is still going are kept, as its process exists.
  • Containers of other hosts sharing the Docker daemon are kept, as only this host's are checked.
  • Containers without the label, such as those of other tools, are never touched.
  • A process ID that was reused since can only keep containers longer, never remove those of a run that is going.

Testing

Locally, 2 workers in Docker unless noted:

Case Result
SIGTERM to the runner Both containers removed within 2 s, exit code 143
SIGINT to the process group (Ctrl+C) Both containers removed
SIGTERM to a run of scenarios selected by path (single container) Container removed, exit code 143
SIGKILL to the runner 2 containers left, removed by the next run: "Removed 2 Docker containers that earlier runs left behind."
Next run while another run is going, with dummy containers of a dead process on this host, of another host and without the label Only the dead process's container removed
Full suite, 4 workers 113 scenarios passed

A run removed its containers in shutdown functions, which PHP skips when a signal
ends it, so Ctrl+C or a timeout left the database containers running.

Exit through the signal handlers when the pcntl extension is available, so the
shutdown functions run. Label the containers with the host and process of their
run, and remove those of runs on this host whose process is gone before starting
new ones, which covers runs that were killed outright. Containers of runs that are
still going, of other hosts and those without the label are left alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera
schlessera requested a review from a team as a code owner November 2, 2026 09:44
@coderabbitai

coderabbitai Bot commented Nov 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 seconds.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 759ee6e4-8fac-4f02-a7e7-f526bbc30d3a
Commits

Reviewing files that changed from the base of the PR and between 035668f and 4e69782.

Files selected for processing: 2
  • .readme-partials/USING.md
  • utils/behat-parallel.php
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions github-actions Bot added bug Something isn't working scope:testing Related to testing labels Nov 2, 2026
@codecov

codecov Bot commented Nov 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@schlessera
schlessera merged commit cb149a3 into main Nov 2, 2026
72 checks passed
@schlessera
schlessera deleted the feature/docker-cleanup branch November 2, 2026 09:53
@schlessera schlessera added this to the 5.4.3 milestone Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working scope:testing Related to testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant