fix(linux/publish): release the Avahi client when the poll loop stops - #5545
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c910ae161
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| client.reset(); | ||
| group = nullptr; |
There was a problem hiding this comment.
Add regression coverage for Avahi cleanup
This new exit-path cleanup is the behavior the fix depends on, but the commit only changes src/platform/linux/publish.cpp and adds no test that exercises a failure path where simple_poll_quit() makes the poll loop return and then verifies the client is released and the entry group is cleared. Please add focused coverage, e.g. with stubbed Avahi function pointers, so this resource-leak fix cannot silently regress.
Useful? React with 👍 / 👎.
`poll` and `client` are namespace-scope, so they are only destroyed at process exit. When publishing fails, create_services()' fail_guard calls simple_poll_quit() and the poll thread exits, but the client - and its libdbus connection to the system bus - stays open with its match rules installed and nobody left to read it. On dbus-broker the resulting queue is charged to the per-UID quota, so after a few days of uptime the quota is exhausted and the broker starts disconnecting unrelated peers owned by the same user. Release the client once simple_poll_loop() returns, and clear `group` with it since the entry group is owned by the client.
6c910ae to
d0328a8
Compare
Bundle ReportBundle size has no change ✅ |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5545 +/- ##
==========================================
+ Coverage 33.80% 33.84% +0.04%
==========================================
Files 104 104
Lines 25081 25089 +8
Branches 11094 11097 +3
==========================================
+ Hits 8478 8492 +14
+ Misses 15626 15375 -251
- Partials 977 1222 +245
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 35 files with indirect coverage changes Continue to review full report in Codecov by Harness.
|
Screenshot ComparisonPR #5545 screenshots vs Matrix:
|


































































Description
Sunshine leaks its Avahi D-Bus connection when mDNS publishing is refused.
pollandclientare namespace-scope, so they live until process exit. Whenentry_group_add_servicefails,create_services()'sfail_guardcallssimple_poll_quit()and the poll thread exits — butclientis never reset. Its libdbus connection to the system bus stays open, with its match rules installed and nothing left to read it.dbus-broker charges that queue to the per-UID quota. After a few days of uptime the quota is exhausted and the broker starts disconnecting unrelated peers owned by the same user. On my machine that killed Steam — exit code 0, no crash dump, no hint it had anything to do with Sunshine.
Reproduced with avahi-daemon running
disable-publishing=yes:Unpatched, 43 minutes later: the bus socket holds
Recv-Q32983, byte-identical across probes 10 s apart, and the broker's side sits at 213760 — its write buffer is full (net.core.wmem_defaultis 212992 here). Everything queued past that accumulates inside the broker, which is what the quota counts. Growth ~5.7 KB/min. It ends in:Patched, same version and same config, same refusal logged: the connection is gone — 4 bus sockets instead of 6, all
Recv-Q0, still 0 after 15 minutes.The fix releases the client once
simple_poll_loop()returns; that call only returns when publishing has stopped for good.groupis cleared with it, since the entry group is owned by the client and would dangle on a laterstart().pollis released in~deinit_t()after the thread is joined.Environment: Sunshine 2026.516.143833, NixOS, dbus-broker 37 (
--max-bytes 536870912).Testing: verified by the A/B above on a live system. I did not add a unit test — reproducing this needs a running avahi-daemon that refuses publishing and a system bus that accounts queue bytes per UID, which I could not express in the existing suite.
Screenshot
N/A — not a UI change.
Issues Fixed or Closed
None — I did not find an existing issue for this. Happy to open one if you would rather track it separately.
Roadmap Issues
Type of Change
Checklist
AI Usage
See our AI usage policy.