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

Improve signal handling - Make the state machine context aware #231

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

Conversation

upils
Copy link
Collaborator

@upils upils commented Jul 5, 2024

Hitting Ctrl-C will currently immediately kill ubuntu-image and every underlying subcommand. This is problematic because several states are mounting some important directories and thus cancelling the execution could leave the system in a broken state. Unaware users could then try to clean the work directory and thus remove important directories from their system.

To properly cancel the execution, we need to:

  • properly catch signals to cancel the execution
  • communicate to the state machine cancellation was requested via a context
  • properly stop subcommands, using exec.CommandContext
  • execute "cancellation actions" when a stateFunc is interrupted.

This PR is dealing with the first 2 steps.

Copy link

codecov bot commented Jul 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.00%. Comparing base (43771d1) to head (e58f999).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #231      +/-   ##
==========================================
+ Coverage   93.99%   94.00%   +0.01%     
==========================================
  Files          18       18              
  Lines        3412     3418       +6     
==========================================
+ Hits         3207     3213       +6     
  Misses        132      132              
  Partials       73       73              
Flag Coverage Δ
unittests 94.00% <100.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.

@upils upils force-pushed the improve-signal-handling branch from 23a82a4 to abab7f3 Compare July 16, 2024 12:03
@upils upils self-assigned this Jul 16, 2024
@upils upils force-pushed the improve-signal-handling branch from abab7f3 to 99f2fb3 Compare July 24, 2024 15:21
@upils upils requested a review from sil2100 July 26, 2024 08:04
upils added 3 commits August 14, 2024 14:28
For now we are not doing anything with the context but this is the first step to enable proper cancellation.
Also adding a cancelFuncs in stateMachine is to prepare calling these functions to properly clean things when a stateFuncs is stopped.

Signed-off-by: Paul Mars <[email protected]>
@upils upils force-pushed the improve-signal-handling branch from 99f2fb3 to e58f999 Compare August 14, 2024 12:34
ch := make(chan os.Signal, 2)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)

go func() {

Choose a reason for hiding this comment

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

Do you already have plans for the signal handler? Like, if the cleanup process blocks or takes too long for some reason (like trying to call umount on a problematic mounting point (I don't know, imagine a bad disk or NFS mount that got stuck)) it should be possible to still interrupt the tool (you could kill -9 it anyway).

If you ctrl+c again while the signal handler is running nothing will happen because the signal is being caught. You could handle subsequent ctrl+c's and inform the user that the tool is shutting down but if they want to stop it anyway they can hit ctrl+c again.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes! That is the plan in the following PR #235 (still very much WIP)

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