Skip to content

Commit 62e54d7

Browse files
authored
Merge pull request #1910 from mrrobot47/feat/docker-check-retry
Add retry mechanism with exponential backoff for Docker availability check
2 parents 5f7dd01 + 9decf6d commit 62e54d7

File tree

1 file changed

+23
-9
lines changed

1 file changed

+23
-9
lines changed

php/EE/Runner.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,25 @@ public function check_requirements( $show_error = true ) {
9292
$status = true;
9393
$error = [];
9494

95-
$docker_running_cmd = 'docker ps > /dev/null';
96-
if ( ! EE::exec( $docker_running_cmd ) ) {
97-
$status = false;
98-
$docker_running = false;
99-
$error[] = 'Docker not installed or not running.';
95+
// Retry logic for Docker availability check to handle transient failures under system load.
96+
$docker_running_cmd = 'docker ps > /dev/null 2>&1';
97+
$max_retries = 4;
98+
99+
for ( $attempt = 1; $attempt <= $max_retries; $attempt++ ) {
100+
if ( EE::exec( $docker_running_cmd ) ) {
101+
break; // Docker is available, exit retry loop.
102+
}
103+
104+
if ( $attempt < $max_retries ) {
105+
$retry_delay = pow( 2, $attempt - 1 ); // Exponential backoff: 1s, 2s, 4s
106+
EE::debug( "Docker check failed (attempt {$attempt}/{$max_retries}), retrying in {$retry_delay}s...", 'bootstrap' );
107+
sleep( $retry_delay );
108+
} else {
109+
// All retries exhausted.
110+
$status = false;
111+
$docker_running = false;
112+
$error[] = "Docker not installed or not running (checked {$max_retries} times).";
113+
}
100114
}
101115

102116
$docker_compose_installed = 'command -v docker-compose > /dev/null';
@@ -749,17 +763,17 @@ private function set_alias( $alias ) {
749763

750764
public function start() {
751765

766+
EE::debug( $this->_global_config_path_debug, 'bootstrap' );
767+
EE::debug( $this->_project_config_path_debug, 'bootstrap' );
768+
EE::debug( 'argv: ' . implode( ' ', $GLOBALS['argv'] ), 'bootstrap' );
769+
752770
$this->init_ee();
753771

754772
// Enable PHP error reporting to stderr if testing.
755773
if ( getenv( 'BEHAT_RUN' ) ) {
756774
$this->enable_error_reporting();
757775
}
758776

759-
EE::debug( $this->_global_config_path_debug, 'bootstrap' );
760-
EE::debug( $this->_project_config_path_debug, 'bootstrap' );
761-
EE::debug( 'argv: ' . implode( ' ', $GLOBALS['argv'] ), 'bootstrap' );
762-
763777
if ( $this->alias ) {
764778
if ( '@all' === $this->alias && ! isset( $this->aliases['@all'] ) ) {
765779
EE::error( "Cannot use '@all' when no aliases are registered." );

0 commit comments

Comments
 (0)