Skip to content

fix(linux/publish): release the Avahi client when the poll loop stops - #5545

Merged
ReenigneArcher merged 1 commit into
LizardByte:masterfrom
nikzasel:fix/avahi-client-leak
Aug 24, 2026
Merged

fix(linux/publish): release the Avahi client when the poll loop stops#5545
ReenigneArcher merged 1 commit into
LizardByte:masterfrom
nikzasel:fix/avahi-client-leak

Conversation

@nikzasel

Copy link
Copy Markdown
Contributor

Description

Sunshine leaks its Avahi D-Bus connection when mDNS publishing is refused.

poll and client are namespace-scope, so they live until process exit. When entry_group_add_service fails, create_services()'s fail_guard calls simple_poll_quit() and the poll thread exits — but client is 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:

[2026-08-22 17:01:06.262]: Info: Adding avahi service dev
[2026-08-22 17:01:06.262]: Error: Failed to add _nvstream._tcp service: Not permitted

Unpatched, 43 minutes later: the bus socket holds Recv-Q 32983, byte-identical across probes 10 s apart, and the broker's side sits at 213760 — its write buffer is full (net.core.wmem_default is 212992 here). Everything queued past that accumulates inside the broker, which is what the quota counts. Growth ~5.7 KB/min. It ends in:

dbus-broker: UID 1000 exceeded its 'bytes' quota on UID 1000.
dbus-broker: Peer :1.127 is being disconnected as it does not have the resources to receive a signal it subscribed to.

Patched, same version and same config, same refusal logged: the connection is gone — 4 bus sockets instead of 6, all Recv-Q 0, 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. group is cleared with it, since the entry group is owned by the client and would dangle on a later start(). poll is 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

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Unit tests have been added or updated for any new or modified functionality

AI Usage

See our AI usage policy.

  • None: No AI tools were used in creating this PR
  • Light: AI provided minor assistance (formatting, simple suggestions)
  • Moderate: AI helped with code generation or debugging specific parts
  • Heavy: AI generated most or all of the code changes

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +594 to +595
client.reset();
group = nullptr;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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.
@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@sonarqubecloud

Copy link
Copy Markdown

@codecov

codecov Bot commented Aug 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 33.84%. Comparing base (233bb50) to head (d0328a8).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/platform/linux/publish.cpp 0.00% 5 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
Archlinux 0.00% <0.00%> (ø)
FreeBSD-amd64 19.51% <0.00%> (-0.01%) ⬇️
Homebrew-macos-14 30.76% <ø> (ø)
Homebrew-macos-15 31.47% <ø> (ø)
Homebrew-macos-26 31.59% <ø> (+0.01%) ⬆️
Homebrew-ubuntu-24.04 20.82% <0.00%> (-0.01%) ⬇️
Linux-AppImage 20.23% <0.00%> (-0.01%) ⬇️
Windows-AMD64 25.78% <ø> (ø)
Windows-ARM64 21.66% <ø> (ø)
macOS-arm64 25.57% <ø> (ø)
macOS-x86_64 26.22% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/platform/linux/publish.cpp 0.00% <0.00%> (ø)

... and 35 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 233bb50...d0328a8. Read the comment docs.

@github-actions

github-actions Bot commented Aug 23, 2026

Copy link
Copy Markdown
Last Updated 2026-08-24 03:02:11 UTC
Source Run CI Run #5087
Commit d0328a8d142def70d1d189acd1e242287fd82721

Screenshot Comparison

PR #5545 screenshots vs screenshots baseline.

Matrix: AppImage

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-AMD64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: Windows-ARM64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-arm64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

Matrix: macOS-x86_64

Image Baseline PR
sunshine_tray_initial.png
sunshine_tray_menu.png
sunshine_tray_pairing_request.png
sunshine_tray_paused.png
sunshine_tray_stopped.png
sunshine_tray_streaming.png
sunshine_tray_tooltip.png

@ReenigneArcher
ReenigneArcher merged commit e575917 into LizardByte:master Aug 24, 2026
112 of 114 checks passed
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.

2 participants