@@ -77,27 +77,35 @@ public function retry(Closure $closure, bool $idempotent)
7777 $ startTime = microtime (true );
7878 $ retryCount = 0 ;
7979 $ lastException = null ;
80- $ deadline = is_null ($ this ->timeoutMs ) ? PHP_INT_MAX : $ startTime + $ this ->timeoutMs / 1000 ;
80+ if (is_null ($ this ->timeoutMs )) {
81+ $ deadline = PHP_INT_MAX ;
82+ } else {
83+ $ deadline = $ startTime + $ this ->timeoutMs / 1000 ;
84+ }
8185 $ this ->logger ->debug ("YDB: begin retry function. Deadline: $ deadline " );
8286 do {
83- $ this ->logger ->debug ("YDB: Run user function. Retry count: $ retryCount. s: " . (microtime (true ) - $ startTime ));
87+ $ this ->logger ->debug ("YDB: Run user function. Retry count: $ retryCount. s: " . (microtime (true ) - $ startTime ));
8488 try {
8589 return $ closure ();
8690 } catch (\Exception $ e ) {
87- $ this ->logger ->debug ("YDB: Received exception: " . $ e ->getMessage ());
91+ $ this ->logger ->debug ("YDB: Received exception: " . $ e ->getMessage ());
8892 $ lastException = $ e ;
89- if (!$ this ->canRetry ($ e , $ idempotent )){
90- break ;
93+ if (!$ this ->canRetry ($ e , $ idempotent )) {
94+ $ this ->logger ->error ("YDB: Received non-retryable exception in retry. ms: "
95+ . ((microtime (true ) - $ startTime ) * 1000 ) . "Retry count: $ retryCount " );
96+ throw $ lastException ;
97+ }
98+ $ delay = $ this ->retryDelay ($ retryCount , $ this ->backoffType (get_class ($ e ))) * 1000 ;
99+ if (microtime (true ) + $ delay / 1000000 > $ deadline ) {
100+ $ this ->logger ->error ("YDB: Timeout retry function. ms: "
101+ . ((microtime (true ) - $ startTime ) * 1000 ) . "Retry count: $ retryCount " );
102+ throw $ lastException ;
91103 }
92104 $ retryCount ++;
93- $ delay = $ this ->retryDelay ($ retryCount , $ this ->backoffType (get_class ($ e )))*1000 ;
94105 $ this ->logger ->debug ("YDB: Sleep $ delay microseconds before retry " );
95106 usleep ($ delay );
96107 }
97- } while (microtime (true ) < $ deadline );
98- $ this ->logger ->error ("YDB: Timeout retry function. ms: "
99- .((microtime (true )-$ startTime )*1000 ). "Retry count: $ retryCount " );
100- throw $ lastException ;
108+ } while (true );
101109 }
102110
103111 /**
0 commit comments