Build: Add retry logic to env:install for database connection race condition#10834
Build: Add retry logic to env:install for database connection race condition#10834kraftbj wants to merge 1 commit intoWordPress:trunkfrom
Conversation
The `wp config create` command can fail with "Connection refused" when the database container reports healthy but isn't yet accepting connections. This race condition causes intermittent CI failures. Add `wp_cli_with_retry()` function with exponential backoff to handle database startup timing issues gracefully.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
This PR adds retry logic with exponential backoff to the
wp config createcommand intools/local-env/scripts/install.jsto handle intermittent database connection failures during environment setup.The Problem
The
env:installscript fails intermittently with "Database connection error (2002) Connection refused" because:mysqladmin ping) passes when the database process is runningwp config createcommand runs immediately without any waitThis causes random CI job failures across different PHP/MariaDB combinations.
Approach Chosen: Application-Level Retry
This PR adds a
wp_cli_with_retry()function that retries theconfig createcommand with exponential backoff (1s, 2s, 4s, 8s, 16s).Pros:
docker-compose.ymlCons:
install.jsAlternative Considered: Improved Docker Healthcheck
Change the healthcheck in
docker-compose.ymlfrom ping-based to connection-based:Pros:
Cons:
Trac ticket: https://core.trac.wordpress.org/ticket/64579
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.