PostHog / posthog

🦔 PostHog provides open-source product analytics, session recording, feature flagging and A/B testing that you can self-host.
https://posthog.com
Other
21.24k stars 1.26k forks source link

fix(batch-exports): Set queries to cancel after disconnect #25248

Closed tomasfarias closed 4 days ago

tomasfarias commented 1 week ago

Problem

Batch exports can be cancelled or fail for whatever reason, even reasons beyond query execution. In those cases, we should make sure we at least attempt to cancel queries on ClickHouse's side to avoid overloading the cluster if we continuously fail and retry the same heavy queries.

Changes

Enable setting cancel_http_readonly_queries_on_client_close. Since all batch export queries are just a SELECT this should take care of cancelling them once we disconnect the client.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?