Bird
0
0

Identify the issue in this retry logic:

medium📝 Analysis Q7 of 15
Microservices - Resilience Patterns
Identify the issue in this retry logic:
max_retries = 4
base_delay = 100
for retry in range(max_retries):
  delay = base_delay * (2 ** retry)
  if retry == max_retries:
    print("Retries exhausted")
  else:
    print(f"Waiting {delay}ms before retry")
AThe condition retry == max_retries is never true inside the loop
BThe delay calculation should use addition instead of multiplication
CThe loop should start from 1 instead of 0
DThe base_delay should be doubled each iteration manually
Step-by-Step Solution
Solution:
  1. Step 1: Analyze loop range

    range(max_retries) iterates from 0 to max_retries - 1, so retry == max_retries never occurs.
  2. Step 2: Impact

    The "Retries exhausted" message will never print inside the loop.
  3. Final Answer:

    The condition retry == max_retries is never true inside the loop -> Option A
  4. Quick Check:

    Loop index never equals max_retries [OK]
Quick Trick: Loop index max is max_retries - 1, not max_retries [OK]
Common Mistakes:
MISTAKES
  • Expecting loop variable to reach max_retries
  • Incorrect delay calculation assumptions
  • Misunderstanding loop ranges

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes