Skip to content

fix(qt): clean shutdown by using QueuedConnection and calling QApplication::quit#138

Closed
solidv wants to merge 1 commit into
LizardByte:masterfrom
solidv:master
Closed

fix(qt): clean shutdown by using QueuedConnection and calling QApplication::quit#138
solidv wants to merge 1 commit into
LizardByte:masterfrom
solidv:master

Conversation

@solidv
Copy link
Copy Markdown

@solidv solidv commented May 30, 2026

Description

Used AI to fix the bug, i'm not a developer. Seems to be working fine. Hope this can help to analyze the root cause.

Screenshot

Issues Fixed or Closed

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

  • 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

@sonarqubecloud
Copy link
Copy Markdown

@solidv solidv changed the title Fix clean shutdown by using QueuedConnection and calling QApplication… fix: Fix clean shutdown by using QueuedConnection and calling QApplication… May 30, 2026
@ReenigneArcher
Copy link
Copy Markdown
Member

@Kishi85 could you review?

@ReenigneArcher ReenigneArcher changed the title fix: Fix clean shutdown by using QueuedConnection and calling QApplication… fix(qt): clean shutdown by using QueuedConnection and calling QApplication::quit May 30, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 30, 2026

❌ 3 Tests Failed:

Tests completed Failed Passed Skipped
38 3 35 0
View the top 3 failed test(s) by shortest run time
TrayLinuxCoverageTest::SimulateMenuClickSkipsNonTriggerableActions
Stack Traces | 0.005s run time
.../tests/unit/test_tray_linux.cpp:103
Expected equality of these values:
  g_menu_callback_count
    Which is: 0
  2
TrayLinuxCoverageTest::TrayExitCausesLoopToReturnExitCode
Stack Traces | 0.006s run time
.../tests/unit/test_tray_linux.cpp:176
Expected equality of these values:
  loopResult
    Which is: 0
  -1
TrayTest::TestMenuCallbackAfterNotificationUpdate
Stack Traces | 0.528s run time
.../tests/unit/test_tray.cpp:744
Expected equality of these values:
  callbackCount
    Which is: 1
  2

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@github-actions
Copy link
Copy Markdown

Last Updated 2026-05-30 01:37:20 UTC
Source Run CI Run #626
Commit c7dd24ec2ccb0484326a047aa1b36db3f73c9f1b

Screenshot Comparison

PR #138 screenshots vs screenshots baseline.

Matrix: Linux-qt5

Image Baseline PR
tray_icon_initial.png
tray_icon_svg.png
tray_icon_themed.png
tray_menu_checkbox_checked.png
tray_menu_checkbox_unchecked.png
tray_menu_left_click.png
tray_menu_shown.png
tray_notification_displayed.png
tray_notification_themed_icon.png

Matrix: Linux-qt6

Image Baseline PR
tray_icon_initial.png
tray_icon_svg.png
tray_icon_themed.png
tray_menu_checkbox_checked.png
tray_menu_checkbox_unchecked.png
tray_menu_left_click.png
tray_menu_shown.png
tray_notification_displayed.png
tray_notification_themed_icon.png

Matrix: Windows

Image Baseline PR
tray_icon_initial.png
tray_menu_checkbox_checked.png
tray_menu_checkbox_unchecked.png
tray_menu_shown.png
tray_notification_displayed.png

Matrix: macOS

Image Baseline PR
tray_icon_initial.png
tray_menu_checkbox_checked.png
tray_menu_checkbox_unchecked.png
tray_menu_shown.png
tray_notification_displayed.png

@Kishi85
Copy link
Copy Markdown

Kishi85 commented May 30, 2026

Looking at the screenshots this breaks tests. If I'd have to guess that's because of that QApplication::exit().

From a logical standpoint the tray library is doing everything correct. It should not really have to shutdown QApplication (at least in QtTrayMenu class) as you could in theory use it in conjunction with other Qt stuff that might continue to run if you kill the tray itself.

The main issue is Sunshine's hang detection (once again, same as for my async tray implementation going sideways) so I'm not even sure if we have to fix anything in tray or rather should fix the callback so that it disables hang detection upon shutting down sunshine to prevent it detecting a non-existent hang due to shutdown.

I'll have to look at the issue and also Sunshine's exit action callback in detail but this is definitely a good pointer on what's going on due to explicitly changing the exit signal to QueuedConnection (instead of AutoConnection so it's forcefully run async without blocking) and adding an explicit QApplication::exit().
As always with this much multi-threading (QtMainLoop, Sunshine's tray thread and Sunshine's other threads here to contend with) it can be a pain to find the real reason for such issues and fixing them properly. I'll likely have to attach the debugger to this one directly in Sunshine and hopefully be able to reproduce the issue that way.

@Kishi85
Copy link
Copy Markdown

Kishi85 commented May 30, 2026

See LizardByte/Sunshine#5213 (comment) for a root analysis. This PR should not be needed to fix the issue properly as it's caused by Sunshine calling tray_loop with a different assumption than what it really does.

UPDATE:
I think I'd rather add QApplication::exit() to tray_quit() in case tray_loop(1) was called blocking.
I'd also like to see this properly fixed on Sunshine's side as well so other event processors (if there are ever any) in Sunshine's main thread loop cannot get stuck due to tray blocking indefinitely.

UPDATE2: See #139 for a cleaner solution that only breaks the QtMainLoop when it was started during loop(1). This was definitely missing before and can cause the described Sunshine issues.

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.

3 participants