Skip to content

Conversation

@frankie567
Copy link

Description

The Dramatiq middleware was missing the after_skip_message hook, which is triggered in place of after_process_message when SkipMessage is raised.

Thus, the isolated scope and transaction that are opened in before_process_message were never closed; leading to a memory leak particularly visible in a context where lot of messages are skipped.

The fix is simply to assign after_skip_message to after_process_message, so the teardown logic is triggered. This pattern is used in the Dramatiq code base.

Issues

@frankie567 frankie567 requested a review from a team as a code owner January 20, 2026 13:33
@github-actions
Copy link
Contributor

github-actions bot commented Jan 20, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Bug Fixes 🐛

  • fix(dramatiq): cleanup isolated scope and transaction when message is skipped by frankie567 in #5346

🤖 This preview updates automatically when you update the PR.

… skipped

The Dramatiq middleware was missing the [`after_skip_message` hook](https://dramatiq.io/reference.html#dramatiq.Middleware.after_skip_message),
which is triggered in place of [`after_process_message`](https://dramatiq.io/reference.html#dramatiq.Middleware.after_skip_message)
when [`SkipMessage`](https://dramatiq.io/reference.html#dramatiq.middleware.SkipMessage) is raised.

Thus, the isolated scope and transaction that are opened in [`before_process_message`](https://dramatiq.io/reference.html#dramatiq.Middleware.before_process_message) were never closed; leading to a memory leak particularly visible in a context where lot of messages are skipped.

The fix is simply to assign `after_skip_message` to `after_process_message`, so the teardown logic is triggered. This pattern is used in the [Dramatiq code base](https://github.com/Bogdanp/dramatiq/blob/143aaa228521606806a87daefff2d21f88607e70/dramatiq/middleware/time_limit.py#L97).
@frankie567 frankie567 force-pushed the dramatiq-skip-message branch from d3bbb38 to 2ebc4e2 Compare January 20, 2026 13:34
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