Skip to content

Fix feature flag 401 errors causing HTTP request storm#422

Merged
dustinbyrne merged 2 commits intoPostHog:masterfrom
GabiGrin:fix/feature-flag-401-request-storm
Feb 4, 2026
Merged

Fix feature flag 401 errors causing HTTP request storm#422
dustinbyrne merged 2 commits intoPostHog:masterfrom
GabiGrin:fix/feature-flag-401-request-storm

Conversation

@GabiGrin
Copy link
Contributor

@GabiGrin GabiGrin commented Feb 4, 2026

Summary

  • Set feature_flags = [] on 401 error to prevent repeated HTTP requests
  • Matches existing behavior for 402 errors

Fixes #421

Set feature_flags = [] on 401 error to prevent repeated requests.
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 4, 2026

Additional Comments (1)

posthog/client.py
flag_cache not cleared on 401 error

The 402 error handler clears the flag_cache (lines 1356-1357), but the 401 handler doesn't. For consistency and to ensure no stale cached evaluations remain, the flag cache should also be cleared here.

                self.feature_flags = []
                self.group_type_mapping = {}
                self.cohorts = {}
                
                # Clear flag cache when unauthorized
                if self.flag_cache:
                    self.flag_cache.clear()
                
                if self.debug:
Prompt To Fix With AI
This is a comment left during a code review.
Path: posthog/client.py
Line: 1338:1345

Comment:
`flag_cache` not cleared on 401 error

The 402 error handler clears the `flag_cache` (lines 1356-1357), but the 401 handler doesn't. For consistency and to ensure no stale cached evaluations remain, the flag cache should also be cleared here.

```suggestion
                self.feature_flags = []
                self.group_type_mapping = {}
                self.cohorts = {}
                
                # Clear flag cache when unauthorized
                if self.flag_cache:
                    self.flag_cache.clear()
                
                if self.debug:
```

How can I resolve this? If you propose a fix, please make it concise.

@dustinbyrne dustinbyrne self-requested a review February 4, 2026 15:29
Copy link
Contributor

@dustinbyrne dustinbyrne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @GabiGrin! This looks great.

@dustinbyrne dustinbyrne merged commit 4f32fa4 into PostHog:master Feb 4, 2026
19 of 22 checks passed
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.

Feature flag errors cause HTTP request storm and thread exhaustion

2 participants