-
Notifications
You must be signed in to change notification settings - Fork 40
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: gracefully shutdown command when shutdown signal is received #493
base: main
Are you sure you want to change the base?
feat: gracefully shutdown command when shutdown signal is received #493
Conversation
crates/tuono/src/watch.rs
Outdated
build_ssr_bundle.stop().await; | ||
run_server.stop().await; | ||
}); | ||
action.quit_gracefully(Signal::Interrupt, std::time::Duration::from_secs(9999)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this automatically stops all the jobs?
https://docs.rs/watchexec/latest/watchexec/action/struct.ActionHandler.html#method.quit_gracefully
crates/tuono/src/watch.rs
Outdated
@@ -116,6 +114,7 @@ pub async fn watch() -> Result<()> { | |||
// watch the current directory | |||
wx.config.pathset(["./src"]); | |||
|
|||
let _ = wx.main().await.into_diagnostic()?; | |||
let _ = wx.main().await.into_diagnostic(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why we remove here the error propagation?
crates/tuono/src/watch.rs
Outdated
rust_server.delete(); | ||
build_ssr_bundle.delete(); | ||
action.quit_gracefully(Signal::Interrupt, std::time::Duration::from_secs(9999)); | ||
eprintln!("Tuono gracefully shutting down..."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need for the users to be informed about this process
eprintln!("Tuono gracefully shutting down..."); |
@jacobhq are you interested in taking a look? |
Yeah if needed. Is there any specific thing that we're stuck on? |
Nono the PR is ready. I was asking if you are interested in reviewing it |
crates/tuono/src/watch.rs
Outdated
action.quit(); | ||
rust_server.delete(); | ||
build_ssr_bundle.delete(); | ||
action.quit_gracefully(Signal::Interrupt, std::time::Duration::from_secs(9999)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have a shorter delay maybe like ~30s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marcalexiei Interesting, it should work out of the box. We may be getting different results, as I'm running Windows 11. However, if the problem persists, could someone investigate it further? I would handle this use case as I did previously by adding a |
I will take a look, as I am also on Win11 :) |
Maybe this can be related: https://docs.rs/tokio/latest/tokio/signal/fn.ctrl_c.html#caveats |
I still get the panic too:
There are some open tasks from code review. Please address those (they may resolve this issue, since we may be stopping stuff twice at the moment), and then see if you can fix this. Happy to help if needed, but please finish code review first :) |
This comment was marked as duplicate.
This comment was marked as duplicate.
I merged with main and now all of the changed files on main are now on this PR now :( Just an FYI - not to sure how to get rid of them all. @jacobhq I did add the resolve the comments about the duration to 30 seconds on it killed the remaining job that I missed. However, I'm still receiving the panic from the open jobs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're in a tricky place.
I would suggest reverting cc78c84
with git reset HEAD~1 --hard
(undoes last commit and deletes changes). Then use update your fork by pulling tuono-labs/tuono main (or Github UI). Let me know if you need help with that.
git merge main
when on this branch to bring in changes. Please don't rebase, as you'll rewrite history, and there's a lot of code review that would be messed up. Resolve the conflicts and commit.
After you have merged main, address code review in a separate commit.
I did add the resolve the comments about the duration to 30 seconds on it killed the remaining job that I missed. However, I'm still receiving the panic from the open jobs.
I will take a look tomorrow. Probably priority is to merge main at the moment.
@jacobhq Thanks for you're help, that was a right PITA! Everything is in order now, if you view all the commits and not individually, you shall see my changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this. Can confirm this works on my machine.
action.quit(); | ||
rust_server.delete(); | ||
build_ssr_bundle.delete(); | ||
build_rust_src.delete(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using .delete()
does work here although I don't think it gracefully shuts down the jobs. @Valerioageno WDYT?
@@ -21,7 +20,6 @@ const DEV_SSR_BIN_SRC: &str = "node_modules\\.bin\\tuono-dev-ssr.cmd"; | |||
const DEV_WATCH_BIN_SRC: &str = "node_modules/.bin/tuono-dev-watch"; | |||
#[cfg(not(target_os = "windows"))] | |||
const DEV_SSR_BIN_SRC: &str = "node_modules/.bin/tuono-dev-ssr"; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add this new line back in
Checklist
Related issue
Fixes: #469
Currently, the dev CLI panics when a user hits CTRL+C.
Overview
Implemented an receiver shutdown to handle async jobs, plus wait till all the process have stopped.
I have created a mpsc::channel to send a shutdown signal to the main watch function, this singal triggers a graceful shutdown of both the rust server and the SSR bundle build.
I have used tokio::spawn ensureing a shutdown process that is executed asynchronously, with explicitly stopping the running server and the ssr bundle.