Repository navigation
packages/django-dramatiq-postgres/broker: fix race condition in broker causing completed tasks to be repeated - #23218
Merged
Conversation
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #23218 +/- ##
==========================================
+ Coverage 93.16% 93.24% +0.08%
==========================================
Files 1035 1036 +1
Lines 60338 60411 +73
Branches 400 400
==========================================
+ Hits 56212 56329 +117
+ Misses 4126 4082 -44
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
rissson
approved these changes
Jun 22, 2026
Contributor
|
🍒 Cherry-pick to |
Contributor
|
|
rissson
pushed a commit
that referenced
this pull request
Jun 22, 2026
…r causing completed tasks to be repeated (cherry-pick #23218 to version-2026.5) (#23257) Co-authored-by: Ryan Pesek <[email protected]> fix race condition in broker causing completed tasks to be repeated (#23218)
kensternberg-authentik
added a commit
that referenced
this pull request
Jun 22, 2026
* main: (30 commits) core, flows: drop maximum-scale=1 from viewport meta (#23261) web: bump vite from 8.0.12 to 8.0.16 in /web (#23129) web: bump the storybook group across 1 directory with 4 updates (#23246) ci: bump actions/checkout from 6.0.3 to 7.0.0 (#23250) core: bump structlog from 25.5.0 to 26.1.0 (#23241) packages/django-dramatiq-postgres/broker: fix race condition in broker causing completed tasks to be repeated (#23218) core, web: update translations (#23237) core: bump pytest from 9.0.3 to 9.1.0 (#23238) core: bump aws-cdk-lib from 2.258.1 to 2.259.0 (#23240) core: bump goauthentik/fips-python from `9b938f7` to `cbec346` in /lifecycle/container (#23242) core: bump ruff from 0.15.17 to 0.15.18 (#23243) ci: bump int128/docker-manifest-create-action from 2.22.0 to 2.23.0 (#23244) core: bump pytest-github-actions-annotate-failures from 0.4.0 to 0.4.1 (#23245) ci: bump softprops/action-gh-release from 3.0.0 to 3.0.1 (#23247) core: bump astral-sh/uv from 0.11.22 to 0.11.23 in /lifecycle/container (#23248) ci: bump taiki-e/install-action from 2.81.11 to 2.82.0 in /.github/actions/setup (#23252) web: bump date-fns from 4.1.0 to 4.4.0 in /web (#23253) core: bump which from 8.0.3 to 8.0.4 (#23254) translate: Updates for project authentik and language ar_AA (#23255) packages/django-postgres-cache: fix naive datetime warning (#23033) ...
rissson
added a commit
that referenced
this pull request
Jun 29, 2026
…r causing completed tasks to be repeated (cherry-pick #23218 to version-2026.2) (#23258) Co-authored-by: Ryan Pesek <[email protected]> Co-authored-by: Marc 'risson' Schmitt <[email protected]> Signed-off-by: Marc 'risson' Schmitt <[email protected]>
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.
Details
Fixes a race in the Postgres Dramatiq broker where a completed task could be picked up again immediately after successful processing.
_post_process_message()removed the task fromin_processingand queued its advisory lock for release before updating the DB row toDONE/REJECTED. Under load, the consumer could briefly see the same non-terminal row again, consume it, and then fail to decode it after the original ack clearedmessagetob"".This showed up in worker logs as:
For affected rows, the task logs showed Task finished processing without errors immediately before the decode failure, and the DB row had octet_length(message) = 0.
This also hardens requeue() so it does not move already terminal DONE/REJECTED rows back to QUEUED.
History
The underlying race appears to have been introduced by #17335, which added the current post-processing flow and removed tasks from in_processing before the terminal DB update.
The visible zero-byte decode symptom became possible after #19340, which intentionally clears successful task messages by storing message = b"".
The current log message was added by #22110, which catches decode failures and rejects the task instead of letting task processing stop.
Changes
Checklist
make all)make docs)