Skip to content
This repository was archived by the owner on Jul 14, 2025. It is now read-only.

Handle SIGTERM properly#183

Open
denverdino wants to merge 1 commit intodeislabs:mainfrom
denverdino:feature/handle_sigterm
Open

Handle SIGTERM properly#183
denverdino wants to merge 1 commit intodeislabs:mainfrom
denverdino:feature/handle_sigterm

Conversation

@denverdino
Copy link
Copy Markdown

Signed-off-by: Li Yi denverdino@gmail.com

Fix #182

Tested in Mac/Linux

$ cargo run -- -c examples/modules.toml
    Finished dev [unoptimized + debuginfo] target(s) in 1.03s
     Running `target/debug/wagi -c examples/modules.toml`
No log_dir specified, using temporary directory /var/folders/jh/x0hxxwzn7j7fhmlh3q3k17x40000gp/T/.tmp9evE6D for logs
Ready: serving on http://127.0.0.1:3000

In the separated terminal

$ kill -15 PROCESS_ID

Signed-off-by: Li Yi <denverdino@gmail.com>
@ghost
Copy link
Copy Markdown

ghost commented Jun 2, 2022

CLA assistant check
All CLA requirements met.

@itowlson
Copy link
Copy Markdown
Contributor

itowlson commented Jun 7, 2022

Sorry for the lack of reply - I've been away. Thanks for this - I'll take a look!

Copy link
Copy Markdown
Contributor

@itowlson itowlson left a comment

Choose a reason for hiding this comment

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

Couple of things, hopefully minor. Thanks!

use hyper::{Body, Response, Server};
use tokio::net::TcpStream;
use tokio_rustls::server::TlsStream;
use tokio::signal::unix::SignalKind;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this work on Windows? Might need to be conditionally compiled...

.await?;
let server = Server::builder(tls::TlsHyperAcceptor::new(&self.address, &tls.cert_path, &tls.key_path).await?)
.serve(mk_svc);
let graceful = server.with_graceful_shutdown(shutdown_signal());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We had problems with with_graceful_shutdown in Spin because it kept the process alive until all connections had closed, which could be a couple of minutes due to keep-alives. See spinframework/spin#73 for the problem and links to relevant Hyper issues, and spinframework/spin#232 for how we solved it there.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support SIGTERM for graceful shutdown in containers

2 participants