Repository navigation
Conversation
When sd_bus_call failed, call_method raised before unref-ing the call message and freeing the sd_bus_error. Any file descriptor appended to the message (type "h") was leaked with it, so a long-running process making failing calls eventually hit EMFILE. get_property never freed its error. Release both in a finally block, and add an e2e test that makes 100 failing calls with an fd argument and checks the fd count stays flat. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
Cleanup preserves ownership and exception handling, with no blocking issues identified; tests were not executed during review.
No open issues 🎉
What changed in this PR
Fixes resource leaks in the D-Bus wrapper when method calls or property reads fail.
Changes:
- Ensures call messages and error resources are released.
- Adds a regression test checking descriptor counts after repeated failing calls.
- Documents the fix in the changelog.
| File | Description |
|---|---|
| pystemd/dbuslib.pyx | Adds guaranteed cleanup using finally blocks. |
| e2e/test_dbus.py | Tests descriptor cleanup across 100 failed calls. |
| CHANGES.md | Records the resource-leak fix. |
Review effort: Balanced
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.
When
sd_bus_callfails,DBus.call_methodraises before unref-ing the call message and freeing thesd_bus_error. Any file descriptor appended to the message (h) leaks with it, so a long-running process that makes failing calls eventually hitsEMFILE.DBus.get_propertynever freed its error at all.This releases both in a
finallyblock and adds an e2e test that makes 100 failing calls with an fd argument and checks the process fd count stays flat.Measured on Debian trixie (systemd 257, Python 3.13), 20,000 failing
StartTransientUnitcalls with an fd argument:The new test fails on
main(116 fds vs. 16) and passes with the fix; the existing unit tests pass.🤖 Generated with Claude Code