@@ -107,14 +107,20 @@ public function createForHypernode(string $hypernode, array $data = []): string
107107 *
108108 * @param string $brancherHypernode Name of the brancher Hypernode
109109 * @param int $timeout Maximum time to wait for availability
110+ * @param int $reachabilityCheckCount Number of consecutive successful checks required
111+ * @param int $reachabilityCheckInterval Seconds between reachability checks
110112 * @return void
111113 * @throws CreateBrancherHypernodeFailedException
112114 * @throws HypernodeApiClientException
113115 * @throws HypernodeApiServerException
114116 * @throws TimeoutException
115117 */
116- public function waitForAvailability (string $ brancherHypernode , int $ timeout = 1500 ): void
117- {
118+ public function waitForAvailability (
119+ string $ brancherHypernode ,
120+ int $ timeout = 1500 ,
121+ int $ reachabilityCheckCount = 6 ,
122+ int $ reachabilityCheckInterval = 10
123+ ): void {
118124 $ latest = microtime (true );
119125 $ timeElapsed = 0 ;
120126 $ resolved = false ;
@@ -175,7 +181,7 @@ public function waitForAvailability(string $brancherHypernode, int $timeout = 15
175181 );
176182 }
177183
178- $ resolved = false ;
184+ $ consecutiveSuccesses = 0 ;
179185 while ($ timeElapsed < $ timeout ) {
180186 $ now = microtime (true );
181187 $ timeElapsed += $ now - $ latest ;
@@ -184,12 +190,37 @@ public function waitForAvailability(string $brancherHypernode, int $timeout = 15
184190 $ connection = @fsockopen (sprintf ("%s.hypernode.io " , $ brancherHypernode ), 22 );
185191 if ($ connection ) {
186192 fclose ($ connection );
187- $ resolved = true ;
188- break ;
193+ $ consecutiveSuccesses ++;
194+ $ this ->log ->info (
195+ sprintf (
196+ 'Brancher Hypernode %s reachability check %d/%d succeeded. ' ,
197+ $ brancherHypernode ,
198+ $ consecutiveSuccesses ,
199+ $ reachabilityCheckCount
200+ )
201+ );
202+
203+ if ($ consecutiveSuccesses >= $ reachabilityCheckCount ) {
204+ break ;
205+ }
206+ sleep ($ reachabilityCheckInterval );
207+ } else {
208+ if ($ consecutiveSuccesses > 0 ) {
209+ $ this ->log ->info (
210+ sprintf (
211+ 'Brancher Hypernode %s reachability check failed, resetting counter (was at %d/%d). ' ,
212+ $ brancherHypernode ,
213+ $ consecutiveSuccesses ,
214+ $ reachabilityCheckCount
215+ )
216+ );
217+ }
218+ $ consecutiveSuccesses = 0 ;
219+ sleep ($ reachabilityCheckInterval );
189220 }
190221 }
191222
192- if (! $ resolved ) {
223+ if ($ consecutiveSuccesses < $ reachabilityCheckCount ) {
193224 throw new TimeoutException (
194225 sprintf ('Timed out waiting for brancher Hypernode %s to become reachable ' , $ brancherHypernode )
195226 );
0 commit comments