Skip to content

Conversation

jasonyuezhang
Copy link
Owner

Fixes SENTRY-FOR-SENTRY-7PYE. The issue was that: Cleanup query failed due to short database statement timeout, which was not overridden for the long-running task.

  • Introduces a context manager unset_statement_timeout to temporarily disable the statement timeout for PostgreSQL connections.
  • Wraps the batch processing loop in ModelDeletionTask.get_objects_to_delete with the unset_statement_timeout context manager to prevent timeouts during long-running cleanup queries.

This fix was generated by Seer in Sentry, triggered by [email protected]. 👁️ Run ID: 117

Not quite right? Click here to continue debugging with Seer.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.


Copied from getsentry#101081
Original PR: getsentry#101081

Copy link

Disable Database Statement Timeout During Long-Running Cleanup Queries

This pull request addresses an issue where long-running cleanup queries could fail due to the default PostgreSQL statement_timeout. It introduces a context manager unset_statement_timeout to temporarily disable the timeout for PostgreSQL connections, and modifies the cleanup batching logic in the deletion component to use this context so that lengthy cleanup tasks complete without premature termination.

Key Changes

• Added the context manager unset_statement_timeout to src/sentry/db/postgres/transactions.py for temporarily setting PostgreSQL's statement_timeout to 0 (unlimited) and restoring it after use.
• Updated the import logic in src/sentry/db/deletion.py to use unset_statement_timeout.
• Modified the batching loop in BulkDeleteQuery.iterator within src/sentry/db/deletion.py to wrap batch deletions with the new timeout-disabling context manager.
• Ensures original timeout value is restored after batch operation completes, and applies logic only for PostgreSQL connections.

Affected Areas

src/sentry/db/postgres/transactions.py
src/sentry/db/deletion.py

This summary was automatically generated by @propel-code-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant