Skip to content

Conversation

@giulio93
Copy link

Motivation

In order to let the an application to gracefully shutdown a cleanup callback function can be run before exiting.

closes https://github.com/arduino/private-tooling-team/issues/351

@giulio93 giulio93 requested a review from dido18 December 19, 2025 16:13
Comment on lines +50 to +54
if cleanup != nil {
if err := cleanup(); err != nil {
return fmt.Errorf("cleanup failed: %w", err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to be clever here. A long cleanup procedure could interfere with the execApp above. If the app is set to have only one instance, the exec above will fail because the app will run the cleanup while the new one starts. I would say that at least the cleanup should be done before the execApp. But I am wondering if the caller should also run its exit code. Run our self os.Exit is risky because it will prevent the caller from running the deferred functions, so maybe something will not be correctly cleaned.

@Xayton
Copy link
Contributor

Xayton commented Dec 22, 2025

Why isn't the CheckForUpdates function simply return nil and let the caller do the restart?
I think this would be cleaner and safer. Of course we need to modify the App Lab code and sync with them.

@Xayton Xayton changed the title Add a cleanup callback Add a cleanup/exit callback to CheckForUpdates Dec 22, 2025
@lucarin91
Copy link
Contributor

lucarin91 commented Dec 22, 2025

Why isn't the CheckForUpdates function simply return nil and let the caller do the restart? I think this would be cleaner and safer. Of course we need to modify the App Lab code and sync with them.

Not only that the caller need to restart the new application instance right after the cleanup and right before the shutdown, but the issue there is that it probably needs to do it after some delay. Who is implementing this delay? We maybe spawn a detached process with a built-in sleep for that.

@Xayton
Copy link
Contributor

Xayton commented Dec 22, 2025

The linked issue contains a new plan in order to improve the update process, that does not require a cleanup or exit callback.

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