fix: add request timeouts to analytics integration wrappers - #8265
Open
bunlongheng wants to merge 8 commits into
Open
fix: add request timeouts to analytics integration wrappers#8265bunlongheng wants to merge 8 commits into
bunlongheng wants to merge 8 commits into
Conversation
|
@bunlongheng is attempting to deploy a commit to the Flagsmith Team on Vercel. A member of the Team first needs to authorize it. |
for more information, see https://pre-commit.ci
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThe 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 💡
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Several third-party integration wrappers issue outbound HTTP requests with no
timeout, sorequestswaits indefinitely for a response:integrations/grafana/grafana.py-requests.postintegrations/new_relic/new_relic.py-requests.postintegrations/dynatrace/dynatrace.py-requests.postintegrations/datadog/datadog.py-session.postintegrations/mixpanel/mixpanel.py-requests.postintegrations/heap/heap.py-requests.postEach of these targets a
base_urlthat is configured per environment/organisation and stored on the integration model.Why it matters
Python
requestswith notimeoutblocks 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.pyusesGITHUB_API_CALLS_TIMEOUTandwebhooks/webhooks.pyusestimeout=10. These analytics/event wrappers were simply missed.Fix
Add a shared
INTEGRATION_REQUEST_TIMEOUT_SECONDS = 10constant inintegrations/common/constants.py(matching the existing 10s webhook timeout) and pass it astimeout=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.Timeoutafter ~10s instead of blocking indefinitely.