civis-python icon indicating copy to clipboard operation
civis-python copied to clipboard

[CIVIS-11753] FIX prevent infinite recursion in retry logic when Retry-After header is missing

Open mattyb opened this issue 6 months ago • 0 comments

The retry_request function was repeatedly wrapping the wait strategy each time it was called with the same retrying object. Since APIClient reuses a single tenacity.Retrying instance across all API calls, this created deeply nested wait_for_retry_after_header wrappers. When the API returned an error without a Retry-After header, the fallback chain would recurse infinitely, exceeding Python's recursion limit.

The fix adds a guard to only wrap the wait strategy once, preserving the intended behavior: use Retry-After when present, otherwise fall back to the user's configured wait strategy (exponential backoff by default).

Added test that simulates 1000 consecutive API calls to verify the fix.

🤖 Generated with Claude Code


  • [ ] (For Civis employees only) Reference to a relevant ticket in the pull request title
  • [ ] Changelog entry added to CHANGELOG.md at the repo's root level
  • [ ] Description of change in the pull request description
  • [ ] If applicable, unit tests have been added and/or updated
  • [ ] The CircleCI builds have all passed

mattyb avatar Oct 24 '25 14:10 mattyb