Skip to content

Commit dbefe7a

Browse files
Copilottdgroot
andcommitted
Optimize sleep calls in SSH reachability check
- Only sleep if there's enough time remaining for another check - Avoid wasting timeout on unnecessary sleeps near the timeout boundary Co-authored-by: tdgroot <1165302+tdgroot@users.noreply.github.com>
1 parent c3e76e2 commit dbefe7a

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/Brancher/BrancherHypernodeManager.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,11 @@ private function checkSshReachability(
143143
if ($consecutiveSuccesses >= $reachabilityCheckCount) {
144144
return true;
145145
}
146-
sleep($reachabilityCheckInterval);
146+
147+
// Only sleep if there's enough time remaining for another check
148+
if ((microtime(true) - $startTime + $reachabilityCheckInterval) < $timeout) {
149+
sleep($reachabilityCheckInterval);
150+
}
147151
} else {
148152
if ($consecutiveSuccesses > 0) {
149153
$this->log->info(
@@ -156,7 +160,11 @@ private function checkSshReachability(
156160
);
157161
}
158162
$consecutiveSuccesses = 0;
159-
sleep($reachabilityCheckInterval);
163+
164+
// Only sleep if there's enough time remaining for another check
165+
if ((microtime(true) - $startTime + $reachabilityCheckInterval) < $timeout) {
166+
sleep($reachabilityCheckInterval);
167+
}
160168
}
161169
}
162170

0 commit comments

Comments
 (0)