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

Program doesn't exit on SIGINT or SIGTERM #26

Open
hardcore-sushi opened this issue Jun 16, 2021 · 2 comments
Open

Program doesn't exit on SIGINT or SIGTERM #26

hardcore-sushi opened this issue Jun 16, 2021 · 2 comments

Comments

@hardcore-sushi
Copy link

When I run see and press CTRL+C (SIGINT) to stop it, it doesn't exit. Even a SIGTERM signal doesn't stop the process. The only way to stop see is to kill it.

It would be nice if see could handle this signals and exit gracefully.

@wyhaya
Copy link
Owner

wyhaya commented Jun 20, 2021

Normally it should exit the process because he is not handling any signals and daemons, what OS are you using?

@hardcore-sushi
Copy link
Author

Oh sorry you're right. It only happens when used in docker, but only when started directly (not using a shell), such as with CMD or ENTRYPOINT instructions. I have the issue with my custom Dockerfile as well as your own. Very strange, maybe a docker issue. However I successfully patched your code so it exits when receiving SIGINT or SIGTERM:

src/main.rs:

+use tokio::signal::unix::{signal, SignalKind};
 
Line 66:
-    bind_tcp(configs).await;
+    tokio::spawn(async move {
+        bind_tcp(configs).await;
+    });
+    let mut sigint = signal(SignalKind::interrupt()).unwrap();
+    let mut sigterm = signal(SignalKind::terminate()).unwrap();
+    tokio::select! {
+        _ = sigint.recv() => println!("SIGINT"),
+        _ = sigterm.recv() => println!("SIGTERM")
+    }

With this patch, the docker container exits with SIGINT when pressing CTRL+C and with SIGTERM when using docker stop.

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

No branches or pull requests

2 participants