Opened 6 weeks ago
Last modified 6 weeks ago
#64579 new defect (bug)
Build: env:install fails intermittently with database connection refused
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | Build/Test Tools | Keywords: | has-patch |
| Focuses: | Cc: |
Description
The env:install script (tools/local-env/scripts/install.js) can fail intermittently with "Database connection error (2002) Connection refused" when the database container reports healthy but isn't yet accepting connections.
Steps to reproduce:
- Run npm run env:start && npm run env:install
- Occasionally fails with connection refused error
Root cause:
The first wp_cli() call runs immediately without waiting for the database:
// Line 13 - runs immediately with no wait wp_cli( config create --dbname=wordpress_develop --dbuser=root --dbpass=password --dbhost=mysql --force );
The Docker healthcheck uses mysqladmin ping / mariadb-admin ping, which can pass before the database is ready to accept authenticated connections from other containers.
This causes intermittent CI failures across random PHP/MariaDB combinations (different jobs fail each run).
Related:
Change History (1)
This ticket was mentioned in PR #10834 on WordPress/wordpress-develop by @kraftbj.
6 weeks ago
#1
- Keywords has-patch added
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.js## Alternative Considered: Improved Docker Healthcheck
Change the healthcheck in
docker-compose.ymlfrom ping-based to connection-based:Pros:
Cons: