fix(subscriptions): Skip non-retryable query exceptions in executor poll#8039
Open
phacops wants to merge 1 commit into
Open
fix(subscriptions): Skip non-retryable query exceptions in executor poll#8039phacops wants to merge 1 commit into
phacops wants to merge 1 commit into
Conversation
The executor consumer's `poll()` only handled `QueryException`s whose cause was a `ClickhouseError`. When the cause was anything else (e.g. `QueryTooLongException`), neither branch ran, nothing was re-raised, and execution fell through to `self.__next_step.submit(transformed_message)` where `transformed_message` had never been assigned, raising `UnboundLocalError`. The same fall-through happened for non-retryable ClickHouse error codes. Treat every non-retryable failure (non-retryable ClickHouse codes and non-ClickHouse causes alike) uniformly: log it, emit the `subscription_executor_nonretryable_error` metric, and skip the message instead of submitting an unassigned value downstream. Only retryable ClickHouse errors are re-raised. Fixes SNUBA-9E1 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Summary
Fixes the
UnboundLocalError: cannot access local variable 'transformed_message'crash in the subscriptions executor consumer, reported in SNUBA-9E1 (2632 occurrences, EAP items subscriptions executor).In
ExecuteQuery.poll(), theexcept QueryExceptionblock only handled exceptions whose__cause__was aClickhouseError:raise SubscriptionQueryException(crash & retry)QueryTooLongException) → fall through with no handlingIn both fall-through cases, execution reached
self.__next_step.submit(transformed_message)whiletransformed_messagehad never been assigned (the assignment is what raised), producing theUnboundLocalError. The reported events areQueryTooLongException("query is 163075 bytes, too long for ClickHouse"), which is non-retryable and not aClickhouseError, so it hit the unhandled path.Fix
Treat every non-retryable failure uniformly — non-retryable ClickHouse error codes and non-ClickHouse causes (like
QueryTooLongException) alike: log the exception, emit thesubscription_executor_nonretryable_errormetric, andcontinueto skip the message instead of submitting an unassigned value downstream. Only retryable ClickHouse errors are re-raised so the consumer crashes and retries.Testing
test_poll_skips_non_retryable_query_exceptionreproducing the SNUBA-9E1 scenario (aQueryExceptioncaused byQueryTooLongException): assertspoll()does not raise, does not callnext_step.submit, and emits the non-retryable error metric.test_execute_query_exception(retryable error →SubscriptionQueryException) still passes.Fixes SNUBA-9E1
🤖 Generated with Claude Code
Agent transcript: https://claudescope.sentry.dev/share/SkrksjFrrBLx2z5LtHtzExnDKAalhvyk2gd41CZYyy0