Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions crates/lance-context-master/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,34 @@ async fn main() {

let listener = TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app)
.with_graceful_shutdown(shutdown_signal())
.with_graceful_shutdown(wait_for_shutdown_signal())
.await
.unwrap();
}

async fn shutdown_signal() {
#[cfg(unix)]
async fn wait_for_shutdown_signal() {
use tokio::signal::unix::{signal as unix_signal, SignalKind};

// Kubernetes and other process managers stop containers with SIGTERM.
let mut sigterm =
unix_signal(SignalKind::terminate()).expect("failed to install SIGTERM handler");

tokio::select! {
result = tokio::signal::ctrl_c() => {
result.expect("failed to install Ctrl+C handler");
tracing::info!(signal = "SIGINT", "Shutting down");
}
_ = sigterm.recv() => {
tracing::info!(signal = "SIGTERM", "Shutting down");
}
}
}

#[cfg(not(unix))]
async fn wait_for_shutdown_signal() {
tokio::signal::ctrl_c()
.await
.expect("failed to install Ctrl+C handler");
tracing::info!("Shutting down");
tracing::info!(signal = "Ctrl+C", "Shutting down");
}
29 changes: 24 additions & 5 deletions crates/lance-context-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,38 @@ async fn main() {

let listener = TcpListener::bind(&addr).await.unwrap();
axum::serve(listener, app)
.with_graceful_shutdown(shutdown_signal())
.with_graceful_shutdown(wait_for_shutdown_signal())
.await
.unwrap();

// Connections have drained. Deterministically close resident rollout writers
// (whose `ShardWriter` background tasks need an explicit `close().await`)
// Connections have drained. Deterministically close every resident writer
// before the runtime tears down.
state.shutdown().await;
}

async fn shutdown_signal() {
#[cfg(unix)]
async fn wait_for_shutdown_signal() {
use tokio::signal::unix::{signal as unix_signal, SignalKind};

// Kubernetes and other process managers stop containers with SIGTERM.
let mut sigterm =
unix_signal(SignalKind::terminate()).expect("failed to install SIGTERM handler");

tokio::select! {
result = tokio::signal::ctrl_c() => {
result.expect("failed to install Ctrl+C handler");
tracing::info!(signal = "SIGINT", "Shutting down");
}
_ = sigterm.recv() => {
tracing::info!(signal = "SIGTERM", "Shutting down");
}
}
}

#[cfg(not(unix))]
async fn wait_for_shutdown_signal() {
tokio::signal::ctrl_c()
.await
.expect("failed to install Ctrl+C handler");
tracing::info!("Shutting down");
tracing::info!(signal = "Ctrl+C", "Shutting down");
}
7 changes: 7 additions & 0 deletions python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,10 @@ def server() -> Iterator[str]:
proc.wait(timeout=10)
log.seek(0)
print(log.read().decode(errors="replace"))
if os.name == "posix":
# Popen.terminate sends SIGTERM on POSIX. A clean exit
# proves the server reached its graceful-shutdown path.
assert proc.returncode == 0, (
"server did not handle SIGTERM gracefully "
f"(exit code {proc.returncode})"
)
Loading