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: add support for graceful exits #316

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

Conversation

rupansh
Copy link

@rupansh rupansh commented Jul 15, 2024

This adds a new flag --graceful-exit, which sends SIGTERM signal to the server process on unix hosts and Ctrl+Break on windows.

Note that for windows, I only checked the compilation. so testing on windows would be greatly appreciated.

@rupansh rupansh marked this pull request as ready for review July 15, 2024 02:29
@rupansh
Copy link
Author

rupansh commented Jul 15, 2024

I fired up a windows VM for testing and found that CTRL+C event doesn't work. Applications must handle ctrl+break on windows for graceful exits when spawn via cargo leptos

here's the termination future I passed to with_graceful_shutdown in axum:

    let terminate = {
        use tokio::signal;

        let ctrl_c = async {
            signal::ctrl_c()
                .await
                .expect("failed to install Ctrl+C handler");
        };

        #[cfg(unix)]
        let terminate = async {
            signal::unix::signal(signal::unix::SignalKind::terminate())
                .expect("failed to install signal handler")
                .recv()
                .await;
        };

        #[cfg(windows)]
        let terminate = async {
             signal::windows::ctrl_break()
                 .expect("failed to install Ctrl+Break handler")
		     .recv()
                 .await;
	  };

        async {
            tokio::select! {
                _ = ctrl_c => {},
                _ = terminate => {},
            }
            logging::log!("stopping...");
        }
    };
    ```

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.

1 participant