fleet icon indicating copy to clipboard operation
fleet copied to clipboard

Fleet Desktop isn't calling `onExit` as expected

Open gillespi314 opened this issue 1 year ago • 3 comments

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

  1. Start Fleet Desktop and open fleet-desktop logs in console.app on macOS.
  2. pkill fleet-desktop
  3. Observer that the "exit" message we would expect to see inside the onExit function 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.

gillespi314 avatar Aug 12 '24 18:08 gillespi314

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.

dantecatalfamo avatar Oct 21 '24 14:10 dantecatalfamo

pkill by default sends SIGTERM, which is sometimes not handled the same way as SIGINT

dantecatalfamo avatar Oct 21 '24 14:10 dantecatalfamo

The only way I've been able to get onExit to run is by calling systray.Quit()

dantecatalfamo avatar Oct 21 '24 15:10 dantecatalfamo

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.

Screenshot 2024-10-25 at 9 19 28 PM

PezHub avatar Oct 26 '24 04:10 PezHub

Graceful shutdown call, Fleet's desktop cleanses all, Efficient as fall.

fleet-release avatar Nov 12 '24 18:11 fleet-release