Skip to content

fix: Retry flags requests on 502 and 504#208

Closed
marandaneto wants to merge 3 commits into
PostHog:mainfrom
marandaneto:fix/flags-retry-502-504
Closed

fix: Retry flags requests on 502 and 504#208
marandaneto wants to merge 3 commits into
PostHog:mainfrom
marandaneto:fix/flags-retry-502-504

Conversation

@marandaneto

Copy link
Copy Markdown
Member

Summary

  • retry remote /flags/?v=2 evaluations on HTTP 502 and 504 using feature_flag_request_max_retries
  • keep status-code retries opt-in to the flags evaluation request path only
  • add focused specs for 502/504 retry, non-retry statuses, and max-retries opt-out

Testing

  • ruby -c lib/posthog/feature_flags.rb
  • bundle exec rspec spec/posthog/flags_spec.rb
  • bundle exec rubocop lib/posthog/feature_flags.rb spec/posthog/flags_spec.rb

@greptile-apps

greptile-apps Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Comments Outside Diff (1)

  1. spec/posthog/flags_spec.rb, line 342-352 (link)

    P2 Missing exhaustion test for status-code retries at higher retry counts

    The set to a higher count context (max_retries = 3) tests exception-retry exhaustion (4 HTTP calls → re-raises), but there is no parallel test verifying that 502/504 status-code retries also exhaust correctly — i.e., that when 502 occurs on every attempt the method eventually returns the 502 response and stops after max_retries + 1 calls. Without this test, a regression where status-code retries loop indefinitely or bail out early would go undetected.

    Rule Used: When implementing retry logic, include comprehensi... (source)

    Learned From
    PostHog/posthog#32651

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "fix: Retry flags requests on 502 and 504" | Re-trigger Greptile

@marandaneto

Copy link
Copy Markdown
Member Author

Closing in favor of #209, which contains the same changes from a branch in the PostHog/posthog-ruby repository instead of a fork.

@marandaneto marandaneto closed this Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant