Skip to content

Conversation

@kraftbj
Copy link

@kraftbj kraftbj commented Feb 1, 2026

This PR adds retry logic with exponential backoff to the wp config create command in tools/local-env/scripts/install.js to handle intermittent database connection failures during environment setup.

The Problem

The env:install script fails intermittently with "Database connection error (2002) Connection refused" because:

  1. Docker's healthcheck (mysqladmin ping) passes when the database process is running
  2. But the database may not yet be accepting authenticated connections from other containers
  3. The wp config create command runs immediately without any wait

This 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 the config create command with exponential backoff (1s, 2s, 4s, 8s, 16s).

Pros:

  • Handles the actual failure case directly
  • No unnecessary delay when database is ready quickly
  • Self-documenting: the retry logic shows this is a known timing issue
  • Works regardless of how Docker reports container health
  • No changes needed to docker-compose.yml

Cons:

  • Adds ~25 lines of code to install.js
  • Maximum 31 seconds of retries before failing (may not be enough in extreme cases)

Alternative Considered: Improved Docker Healthcheck

Change the healthcheck in docker-compose.yml from ping-based to connection-based:

healthcheck:
  test: ['CMD', 'mysql', '-u', 'root', '-ppassword', '-e', 'SELECT 1']

Pros:

  • Fixes the issue at the source (container health definition)
  • No changes to application code

Cons:

  • Healthcheck runs repeatedly (every 5s) even after startup, adding overhead
  • Different syntax needed for MySQL vs MariaDB vs different MariaDB versions
  • Exposes password in healthcheck command
  • Doesn't help if there are other transient connection issues

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.

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.
@github-actions
Copy link

github-actions bot commented Feb 1, 2026

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props kraftbj.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions
Copy link

github-actions bot commented Feb 1, 2026

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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.

1 participant