You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
In tray mode, SIGTERM and Ctrl+C kill the process without running OnStop or flushing a pending preference save #21
Only the console path installs signal handlers. ConsoleRunner.cs:54-70 hooks Console.CancelKeyPress and PosixSignalRegistration(SIGTERM). The tray path (TrayAppBuilder.RunTray, TrayAppBuilder.cs:458-500, and TrayApplication.cs:98-178) registers neither.
Avalonia 12.1.3 does not handle these signals either. The assemblies contain no references to PosixSignalRegistration, CancelKeyPress or a Unix signal handler. So a tray run killed by kill, systemctl stop, logout, or Ctrl+C in the launching terminal ends through the runtime's default handler:
TrayApplication.Dispose never runs, so the tool's OnStop is skipped. Anything OnStart acquired, such as a sleep inhibitor or a lock, is left for the OS to clean up.
FinishAsync never flushes the debounced preference store. A toggle clicked within the debounce window (500 ms by default) is lost.
This contradicts what the library documents:
README.md:35: "Ctrl+C and SIGTERM both release through the tool's own stop action"
README.md:96: "Ctrl+C and SIGTERM both releasing through OnStop"
The OnStop XML doc on TrayAppBuilder, which says it runs on Ctrl+C and SIGTERM "in both the tray and the console mode"
Failure scenario
The repro was a scratch tool whose OnStart/OnStop print, using a valid PNG icon:
xvfb-run -a dotnet repro.dll --tray, then kill -TERM <pid>: the output is OnStart #1 followed by Terminated. OnStop is never printed.
The same tool run with --no-tray releases through OnStop as documented.
Suggested fix
In RunTray, before StartWithClassicDesktopLifetime:
Register PosixSignalRegistration.Create(PosixSignal.SIGTERM, …) and (PosixSignal.SIGINT, …). Each handler sets context.Cancel = true and posts a lifetime shutdown to Dispatcher.UIThread.
Hook Console.CancelKeyPress, set Cancel = true, and post the same shutdown.
Dispose the registrations and unhook the handler after the run.
Shutting down through the lifetime already runs OnExit, then Dispose, then OnStop, then the FinishAsync flush. That is the same path the Quit menu item takes.
Acceptance criteria
A tray run sent SIGTERM calls OnStop exactly once and exits 0.
A preference toggled just before the signal is persisted.
Ctrl+C in the launching terminal behaves the same way.
The xvfb smoke check, or a README verification step, covers this.
Category: Bug (behaviour contradicts the README and the OnStop XML docs)
Priority: High. Tray mode is the library's main mode. Under kill, systemctl stop or logout, OnStop never runs, so resources that tools take in OnStart (such as sleep inhibitors or locks) are never released, and a preference saved within the debounce window is lost.
Area / suggested assignment:TrayAppBuilder.RunTray and TrayApplication, mirroring the signal handling already in ConsoleRunner
Duplicates: none
In progress: no open PR in TrayApp.
Suggested next step: register SIGTERM/SIGINT handlers and a CancelKeyPress handler that post a lifetime shutdown to Dispatcher.UIThread. That reuses the Quit path. Extend the xvfb smoke check to send kill -TERM and assert that OnStop ran.
Activity
matt-edmondson commentedon Sep 28, 2026
Triage
OnStopXML docs)kill,systemctl stopor logout,OnStopnever runs, so resources that tools take inOnStart(such as sleep inhibitors or locks) are never released, and a preference saved within the debounce window is lost.TrayAppBuilder.RunTrayandTrayApplication, mirroring the signal handling already inConsoleRunnerSuggested next step: register SIGTERM/SIGINT handlers and a
CancelKeyPresshandler that post a lifetime shutdown toDispatcher.UIThread. That reuses the Quit path. Extend the xvfb smoke check to sendkill -TERMand assert thatOnStopran.Generated by Claude Code