@@ -77,22 +77,26 @@ public function retry(Closure $closure, bool $idempotent)
7777 $ startTime = microtime (true );
7878 $ retryCount = 0 ;
7979 $ lastException = null ;
80- while (microtime (true ) < $ startTime + $ this ->timeoutMs / 1000 ) {
80+ $ deadline = is_null ($ this ->timeoutMs ) ? PHP_INT_MAX : $ startTime + $ this ->timeoutMs / 1000 ;
81+ $ this ->logger ->debug ("YDB: begin retry function. Deadline: $ deadline " );
82+ do {
8183 $ this ->logger ->debug ("YDB: Run user function. Retry count: $ retryCount. s: " .(microtime (true ) - $ startTime ));
8284 try {
8385 return $ closure ();
84- } catch (Exception $ e ) {
85- $ this ->logger ->warning ("YDB: Received exception: " .$ e ->getMessage ());
86+ } catch (\Exception $ e ) {
87+ $ this ->logger ->debug ("YDB: Received exception: " .$ e ->getMessage ());
88+ $ lastException = $ e ;
8689 if (!$ this ->canRetry ($ e , $ idempotent )){
87- $ lastException = $ e ;
8890 break ;
8991 }
9092 $ retryCount ++;
91- $ lastException = $ e ;
9293 $ delay = $ this ->retryDelay ($ retryCount , $ this ->backoffType (get_class ($ e )))*1000 ;
94+ $ this ->logger ->debug ("YDB: Sleep $ delay microseconds before retry " );
9395 usleep ($ delay );
9496 }
95- }
97+ } while (microtime (true ) < $ deadline );
98+ $ this ->logger ->error ("YDB: Timeout retry function. ms: "
99+ .((microtime (true )-$ startTime )*1000 ). "Retry count: $ retryCount " );
96100 throw $ lastException ;
97101 }
98102
@@ -111,7 +115,7 @@ protected function alwaysRetry(string $exception)
111115 return in_array ($ exception , self ::$ alwaysRetry );
112116 }
113117
114- protected function canRetry (Exception $ e , bool $ idempotent )
118+ protected function canRetry (\ Exception $ e , bool $ idempotent )
115119 {
116120 return is_a ($ e , RetryableException::class) && ($ this ->alwaysRetry (get_class ($ e )) || $ idempotent );
117121 }
0 commit comments