Skip to content

fix(sentry_apps): Defer resource change webhooks until transaction commit#108561

Draft
sentry[bot] wants to merge 1 commit intomasterfrom
seer/fix/sentry-apps-webhook-race-condition
Draft

fix(sentry_apps): Defer resource change webhooks until transaction commit#108561
sentry[bot] wants to merge 1 commit intomasterfrom
seer/fix/sentry-apps-webhook-race-condition

Conversation

@sentry
Copy link
Contributor

@sentry sentry bot commented Feb 19, 2026

This PR addresses the RetryTaskError occurring in sentry.sentry_apps.tasks.sentry_apps.process_resource_change_bound.

Problem:
The process_resource_change_bound task, responsible for sending webhooks on resource changes (like Group creation), was sometimes failing with Group.DoesNotExist. This happened because the task was enqueued and executed before the database transaction that created the Group had fully committed.

Root Cause:
A race condition existed where the task worker would pick up and attempt to process the webhook task before the corresponding Group record was durably written to the database. When the task tried to fetch the Group using model.objects.get(id=instance_id), it would not find the record, leading to a Group.DoesNotExist exception and subsequent task retries.

Solution:
To resolve this, django.db.transaction.on_commit() has been introduced. The calls to process_resource_change_bound.delay() within process_resource_change_bounds() are now wrapped with transaction.on_commit(). This ensures that the webhook tasks are only added to the queue after the current database transaction has successfully committed. By guaranteeing the Group exists in the database before the task is even queued, we eliminate the race condition and prevent the Group.DoesNotExist errors.

The existing retry mechanism on process_resource_change_bound remains in place to handle any other legitimate transient failures.

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.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants

Comments