Commit d3bbb38
committed
fix(dramatiq): cleanup isolated scope and transaction when message is 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).1 parent d38b378 commit d3bbb38
File tree
2 files changed
+30
-2
lines changed- sentry_sdk/integrations
- tests/integrations/dramatiq
2 files changed
+30
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
191 | 193 | | |
192 | 194 | | |
193 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | 1 | | |
3 | 2 | | |
4 | 3 | | |
| 4 | + | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | | - | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
0 commit comments