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

feat: run lotus-shed commands in context that is cancelled on sigterm #10877

Merged
merged 2 commits into from
May 27, 2023

Conversation

fridrik01
Copy link
Contributor

@fridrik01 fridrik01 commented May 16, 2023

Context
Currently, lotus-shed runs all commands with app.Run. This makes handling handle interrupts difficult or even impossible from the client side (urfave/cli#945). We would like to be able to interrupt (CTRL+C) all our commands such that they can gracefully exit, or if that fails force them to stop (right now we need to do a manual SIGKILL)

This diff
Updates lotus-shed to run all commands with app.RunContext() and pass it a context that we cancel on interrupt from main(). This allows each command to simply check for ctx.Done() and gracefully exit (we can add that incrementally later).

Implementation notes:

  • Calling cancel() does not in all cases gracefully exit as it seems that we not thoroughly check for Done in all codepaths. Therefore, added a second forced stop.
  • I left out other lotus tools from this initial PR, but I can update them as well if this looks good

@fridrik01 fridrik01 marked this pull request as ready for review May 16, 2023 11:48
@fridrik01 fridrik01 requested a review from a team as a code owner May 16, 2023 11:48
go func() {
<-c
cancel()
fmt.Println("Received interrupt, stopping... Press CTRL+C again to force stop")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this message confuses me a bit because it makes me think of SIGSTOP and that we are doing something like that. Changing to "shutting down", and "force shut donw" would remove that confusion.

@fridrik01 fridrik01 merged commit b269a1b into master May 27, 2023
@fridrik01 fridrik01 deleted the lotus-shed-cancel-context branch May 27, 2023 10:30
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