@@ -245,13 +245,16 @@ def ensure_coordinator_ready(self, timeout_ms=None):
245
245
"""
246
246
elapsed = 0.0 # noqa: F841
247
247
begin = time .time ()
248
- def inner_timeout_ms ():
248
+ def inner_timeout_ms (fallback = None ):
249
249
if timeout_ms is None :
250
- return None
250
+ return fallback
251
251
elapsed = (time .time () - begin ) * 1000
252
252
if elapsed >= timeout_ms :
253
253
raise Errors .KafkaTimeoutError ('Timeout attempting to find coordinator' )
254
- return max (0 , timeout_ms - elapsed )
254
+ ret = max (0 , timeout_ms - elapsed )
255
+ if fallback is not None :
256
+ return min (ret , fallback )
257
+ return ret
255
258
256
259
with self ._client ._lock , self ._lock :
257
260
while self .coordinator_unknown ():
@@ -275,7 +278,7 @@ def inner_timeout_ms():
275
278
metadata_update = self ._client .cluster .request_update ()
276
279
self ._client .poll (future = metadata_update , timeout_ms = inner_timeout_ms ())
277
280
else :
278
- time .sleep (min ( inner_timeout_ms (), self .config ['retry_backoff_ms' ]) / 1000 )
281
+ time .sleep (inner_timeout_ms (self .config ['retry_backoff_ms' ]) / 1000 )
279
282
else :
280
283
raise future .exception # pylint: disable-msg=raising-bad-type
281
284
@@ -369,13 +372,16 @@ def ensure_active_group(self, timeout_ms=None):
369
372
370
373
elapsed = 0.0 # noqa: F841
371
374
begin = time .time ()
372
- def inner_timeout_ms ():
375
+ def inner_timeout_ms (fallback = None ):
373
376
if timeout_ms is None :
374
- return None
377
+ return fallback
375
378
elapsed = (time .time () - begin ) * 1000
376
379
if elapsed >= timeout_ms :
377
- raise Errors .KafkaTimeoutError ()
378
- return max (0 , timeout_ms - elapsed )
380
+ raise Errors .KafkaTimeoutError ('Timeout attempting to find coordinator' )
381
+ ret = max (0 , timeout_ms - elapsed )
382
+ if fallback is not None :
383
+ return min (ret , fallback )
384
+ return ret
379
385
380
386
while self .need_rejoin () or self ._rejoin_incomplete ():
381
387
self .ensure_coordinator_ready (timeout_ms = inner_timeout_ms ())
@@ -399,7 +405,7 @@ def inner_timeout_ms():
399
405
while not self .coordinator_unknown ():
400
406
if not self ._client .in_flight_request_count (self .coordinator_id ):
401
407
break
402
- self ._client .poll (timeout_ms = min ( 200 , inner_timeout_ms () ))
408
+ self ._client .poll (timeout_ms = inner_timeout_ms (200 ))
403
409
else :
404
410
continue
405
411
@@ -451,7 +457,7 @@ def inner_timeout_ms():
451
457
continue
452
458
elif not future .retriable ():
453
459
raise exception # pylint: disable-msg=raising-bad-type
454
- time .sleep (min ( inner_timeout_ms (), self .config ['retry_backoff_ms' ]) / 1000 )
460
+ time .sleep (inner_timeout_ms (self .config ['retry_backoff_ms' ]) / 1000 )
455
461
456
462
def _rejoin_incomplete (self ):
457
463
return self .join_future is not None
0 commit comments