Skip to content

fix: add request timeouts to analytics integration wrappers - #8265

Open
bunlongheng wants to merge 8 commits into
Flagsmith:mainfrom
bunlongheng:fix-integration-request-timeouts-sec
Open

fix: add request timeouts to analytics integration wrappers#8265
bunlongheng wants to merge 8 commits into
Flagsmith:mainfrom
bunlongheng:fix-integration-request-timeouts-sec

Conversation

@bunlongheng

Copy link
Copy Markdown

What

Several third-party integration wrappers issue outbound HTTP requests with no timeout, so requests waits indefinitely for a response:

  • integrations/grafana/grafana.py - requests.post
  • integrations/new_relic/new_relic.py - requests.post
  • integrations/dynatrace/dynatrace.py - requests.post
  • integrations/datadog/datadog.py - session.post
  • integrations/mixpanel/mixpanel.py - requests.post
  • integrations/heap/heap.py - requests.post

Each of these targets a base_url that is configured per environment/organisation and stored on the integration model.

Why it matters

Python requests with no timeout blocks forever if the remote host accepts the connection but never responds. These wrappers are invoked on every audit-log event and every identify/trait call. Depending on deployment configuration (ENABLE_POSTPONE_DECORATOR), the call runs either inline in the request/response cycle or in a spawned daemon thread. In the inline case an unresponsive integration endpoint hangs the worker handling a user request; in the threaded case hung threads accumulate without bound. Either way a slow or black-holed integration host degrades availability (CWE-400, uncontrolled resource consumption).

The rest of the codebase already guards against this: integrations/github/client.py uses GITHUB_API_CALLS_TIMEOUT and webhooks/webhooks.py uses timeout=10. These analytics/event wrappers were simply missed.

Fix

Add a shared INTEGRATION_REQUEST_TIMEOUT_SECONDS = 10 constant in integrations/common/constants.py (matching the existing 10s webhook timeout) and pass it as timeout= to each of the outbound calls above. No behavioural change beyond bounding how long a request can hang.

Test

Existing integration wrapper unit tests continue to pass. To verify the change, mock the transport to never respond and assert the call raises requests.exceptions.Timeout after ~10s instead of blocking indefinitely.

@bunlongheng
bunlongheng requested a review from a team as a code owner August 11, 2026 19:15
@bunlongheng
bunlongheng requested review from emyller and removed request for a team August 11, 2026 19:15
@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

@bunlongheng is attempting to deploy a commit to the Flagsmith Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: eb7de42a-89fd-4fd5-a91b-3284571c6d18

📥 Commits

Reviewing files that changed from the base of the PR and between 67853f3 and a44eef2.

📒 Files selected for processing (7)
  • api/integrations/common/constants.py
  • api/integrations/datadog/datadog.py
  • api/integrations/dynatrace/dynatrace.py
  • api/integrations/grafana/grafana.py
  • api/integrations/heap/heap.py
  • api/integrations/mixpanel/mixpanel.py
  • api/integrations/new_relic/new_relic.py

📝 Walkthrough

Walkthrough

The change defines a shared 10-second timeout for outbound integration HTTP requests. Datadog, Dynatrace, Grafana, Heap, Mixpanel, and New Relic POST requests now use this timeout.

Estimated code review effort: 2 (Simple) | ~10 minutes

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the api Issue related to the REST API label Aug 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Issue related to the REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant