Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow once instance of fleet desktop at once #25821

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

dantecatalfamo
Copy link
Member

@dantecatalfamo dantecatalfamo commented Jan 28, 2025

#25396

If some of the following don't apply, delete the relevant line.

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • A detailed QA plan exists on the associated ticket (if it isn't there, work with the product group's QA engineer to add it)
    • Install fleet agent on machine
    • Check logs for fleetd (journalctl -u orbit), somewhere in there you should see a line showing the arguments used to launch fleet desktop
    • Run that command in another terminal, that should launch a second valid copy of fleet desktop
    • See that it closes instantly instead of having two fleet task bar items
    • If you check the fleet desktop logs (~/.local/state/Fleet/fleet-desktop.log), you should see mention of a lock file and that another instance of fleet desktop is active
    • Special cases to check:
      • killing the fleet-desktop process with SIGTERM and SIGKILL
      • killing orbit with SIGTERM and SIGKILL.
      • restarting orbit the usual way in Linux (sudo systemctl restart orbit).
      • pushing a new version of fleet-desktop will properly auto-update it.
      • Test macOS and Windows fleetd restarts (because of changes (1) and (2)).
  • Manual QA for all new/changed functionality
  • For Orbit and Fleet Desktop changes:
    • Orbit runs on macOS, Linux and Windows. Check if the orbit feature/bugfix should only apply to one platform (runtime.GOOS).
    • Manual QA must be performed in the three main OSs, macOS, Windows and Linux.
    • Auto-update manual QA, from released version of component to new version (see tools/tuf/test).

Copy link

codecov bot commented Jan 28, 2025

Codecov Report

Attention: Patch coverage is 0% with 20 lines in your changes missing coverage. Please review.

Project coverage is 63.86%. Comparing base (076fe89) to head (1a1be69).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
orbit/cmd/orbit/orbit.go 0.00% 7 Missing ⚠️
orbit/pkg/platform/platform.go 0.00% 5 Missing ⚠️
orbit/pkg/platform/platform_notwindows.go 0.00% 5 Missing ⚠️
pkg/open/open_linux.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #25821      +/-   ##
==========================================
- Coverage   63.86%   63.86%   -0.01%     
==========================================
  Files        1658     1658              
  Lines      159079   159101      +22     
  Branches     4144     4144              
==========================================
+ Hits       101592   101605      +13     
- Misses      49550    49556       +6     
- Partials     7937     7940       +3     
Flag Coverage Δ
backend 64.69% <0.00%> (-0.01%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dantecatalfamo dantecatalfamo marked this pull request as ready for review January 28, 2025 21:49
@dantecatalfamo dantecatalfamo requested a review from a team as a code owner January 28, 2025 21:49
Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

We already have some functionality to make sure there's only one fleet-desktop process running:

fleet/orbit/cmd/orbit/orbit.go

Lines 1603 to 1609 in da42457

log.Info().Msg("killing any pre-existing fleet-desktop instances")
if err := platform.SignalProcessBeforeTerminate(constant.DesktopAppExecName); err != nil &&
!errors.Is(err, platform.ErrProcessNotFound) &&
!errors.Is(err, platform.ErrComChannelNotFound) {
log.Error().Err(err).Msg("desktop early terminate")
}

  1. Were you able to reproduce the issue?
  2. Do we know why the current functionality is sometimes not working?

@dantecatalfamo
Copy link
Member Author

@lucasmrod I wasn't able to recreate the exact situation the customer was having, but if you launch Fleet Desktop independently using the command line, it will happily open many instances. I'm not entirely sure what the issue was, but it was likely some sort of race condition.

@dantecatalfamo
Copy link
Member Author

Getting fleet-desktop to check a lock should prevent any situation where its launched more than once, regardless of how it happened

@lucasmrod
Copy link
Member

lucasmrod commented Feb 20, 2025

We met with @dantecatalfamo and discussed the following changes (apart from the lock file change):

  1. Move platform.SignalProcessBeforeTerminate invocation to for loop instead before the actual execuser.Run execution.
  2. Make platform.SignalProcessBeforeTerminate kill all instances of fleet-desktop (for Linux), not just one (if the method is used elsewhere then add another method).
  3. Lock file implementation for fleet-desktop only present on Linux.
  4. Add QA notes on the issue to explicitly test:
  • killing the fleet-desktop process with SIGTERM and SIGKILL
  • killing orbit with SIGTERM and SIGKILL.
  • restarting orbit the usual way in Linux (sudo systemctl restart orbit).
  • pushing a new version of fleet-desktop will properly auto-update it.
  • Test macOS and Windows fleetd restarts (because of changes (1) and (2)).

Co-authored-by: Lucas Manuel Rodriguez <[email protected]>
@@ -56,7 +56,7 @@ func SignalProcessBeforeTerminate(processName string) error {

// GetProcessByName gets a single running process object by its name.
Copy link
Member

@lucasmrod lucasmrod Feb 20, 2025

Choose a reason for hiding this comment

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

Let's update the docs (and rename to GetProcessesByName?).

Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

Pending fixing some build issues, otherwise LGTM!

@@ -142,7 +142,7 @@ func SignalProcessBeforeTerminate(processName string) error {
return nil
}

// GetProcessByName gets a single running process object by its name.
// GetProcessesByName gets a single running process object by its name.
// Returns ErrProcessNotFound if the process was not found running.
func GetProcessByName(name string) (*gopsutil_process.Process, error) {
Copy link
Member

Choose a reason for hiding this comment

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

We'll also need to amend the Windows implementation to return all processes, right?

Copy link
Member

Choose a reason for hiding this comment

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

Or document that on Windows we return only one for now (with a TODO in case there are issues in the future)

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like it might cause issues, I'll see about making the Windows implementation return a list as well

Copy link
Member Author

Choose a reason for hiding this comment

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

Added

Copy link
Member

@lucasmrod lucasmrod left a comment

Choose a reason for hiding this comment

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

LGTM!

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