posthog icon indicating copy to clipboard operation
posthog copied to clipboard

fix: prevent runtime error - make timings work with threads

Open aspicer opened this issue 1 year ago • 1 comments

Problem

We're getting runtime errors in trends queries for dictionary changed size during iteration: https://github.com/PostHog/posthog/issues/23306

We're using the same timings object in multi threaded queries and its getting all jumbled up.

Changes

Modify the timings object to handle cloning in order to pass to a thread while maintaining the current key stack.

Change the trends query to not return redundant timing info and to stack it correctly.

How did you test this code?

Wrote a test for it to make sure it's working as intended. Tested in dev. Can't test multi threaded behavior directly (easily).

aspicer avatar Jun 28 '24 18:06 aspicer

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: posthog/hogql/timings.py

Function Unhandled Issue
to_dict RuntimeError: dictionary changed size during iteration posthog.tasks.tasks.process_quer...
Event Count: 96
to_dict TypeError: unsupported operand type(s) for -: 'float' and 'StringDatabaseField' posthog...
Event Count: 1
📄 File: posthog/hogql_queries/insights/trends/trends_query_runner.py (Click to Expand)
Function Unhandled Issue
run IndexError: list index out of range posthog.tasks...
Event Count: 210
calculate RuntimeError: dictionary changed size during iteration posthog.tasks.tasks.process_quer...
Event Count: 96
run ValidationError: 1 validation error for HogQLQueryResponse posthog.tasks.tasks.process_...
Event Count: 34
run CHQueryErrorCannotParseInputAssertionFailed: DB::Exception: Cannot parse NaN.: while converting 'no-10904' to Float64: while executing 'FUNCTI... ...
Event Count: 28
run CHQueryErrorAuthenticationFailed: DB::Exception: Received from ch12.posthog.net:9000. DB::Exception: default: Authentication failed... ...
Event Count: 24
---

Did you find this useful? React with a 👍 or 👎

sentry-io[bot] avatar Jun 28 '24 18:06 sentry-io[bot]