@@ -145,7 +145,7 @@ class ActiveOperationMetric:
145145 op_type : OperationType
146146 uuid : str = field (default_factory = lambda : str (uuid .uuid4 ()))
147147 # create a default backoff generator, initialized with standard default backoff values
148- backoff_generator : TrackedBackoffGenerator | None = field (
148+ backoff_generator : TrackedBackoffGenerator = field (
149149 default_factory = lambda : TrackedBackoffGenerator (initial = 0.01 , maximum = 60 , multiplier = 2 )
150150 )
151151 # keep monotonic timestamps for active operations
@@ -201,15 +201,16 @@ def start_attempt(self) -> ActiveAttemptMetric:
201201 INVALID_STATE_ERROR .format ("start_attempt" , self .state )
202202 )
203203
204- # find backoff value
205- if self .backoff_generator and len (self .completed_attempts ) > 0 :
206- # find the attempt's backoff by sending attempt number to generator
207- # generator will return the backoff time in seconds, so convert to nanoseconds
204+ try :
205+ # find backoff value before this attempt
206+ prev_attempt_idx = len (self .completed_attempts ) - 1
208207 backoff = self .backoff_generator .get_attempt_backoff (
209- len ( self . completed_attempts ) - 1
208+ prev_attempt_idx
210209 )
210+ # generator will return the backoff time in seconds, so convert to nanoseconds
211211 backoff_ns = int (backoff * 1e9 )
212- else :
212+ except IndexError :
213+ # backoff value not found
213214 backoff_ns = 0
214215
215216 self .active_attempt = ActiveAttemptMetric (backoff_before_attempt_ns = backoff_ns )
0 commit comments