Fleet Desktop isn't calling `onExit` as expected
Operating system: macOS 14.5
Fleet version: see more info
💥 Actual behavior
Fleet Desktop is not calling its onExit function as expected when it exits so cleanups (releasing resources, etc.) are not happening as intended.
🧑💻 Steps to reproduce
- Start Fleet Desktop and open
fleet-desktoplogs in console.app on macOS. -
pkill fleet-desktop - Observer that the "exit" message we would expect to see inside the
onExitfunction isn't logged.
🕯️ More info (optional)
We need to implement a more graceful shutdown for Fleet Desktop and cleanup resources (stopping tickers, etc.) in a coordinated manner.
Based on logs for my device, it seems like this issue may have started occurring sometime around January 2024 (that's the last time I find the "exit" message in my logs), but I haven't pinpointed exactly when.
It looks like internally the systray package uses the applicationWillTerminate objective-c method. https://github.com/getlantern/systray/blob/22c167e80905f87867fc05fbe553342578976d7b/systray_darwin.m#L82
It's possible that it doesn't catch and respond to pkill signals, and only works when the application initiated the shutdown. We could write our own signal handlers if that's the case.
pkill by default sends SIGTERM, which is sometimes not handled the same way as SIGINT
The only way I've been able to get onExit to run is by calling systray.Quit()
QA Notes:
Prior to testing the fix, I walked thru the workflow of force quitting fleet desktop and noticed the lack of exit info in the fleet-desktop.log.
After applying the fix and installing fleetd (built w/ tuf) I now see the desired exit info in the logs allowing for a graceful shutdown.
Graceful shutdown call, Fleet's desktop cleanses all, Efficient as fall.