Skip to content

Commit

Permalink
accept SIGTERM as shutdown signal (#1497)
Browse files Browse the repository at this point in the history
* accept SIGTERM as shutdown signal
  • Loading branch information
Geoffroy Couprie authored Aug 16, 2022
1 parent 73cbdcb commit 89b7a96
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
6 changes: 6 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ By [@SimonSapin](https://github.com/SimonSapin)

## 🐛 Fixes

### Accept SIGTERM as shutdown signal ([PR #1497](https://github.com/apollographql/router/pull/1497))

This will make containers stop faster as they will not have to wait until a SIGKILL to stop the router.

By [@Geal](https://github.com/Geal) in https://github.com/apollographql/router/pull/1497

## 🛠 Maintenance

## 📚 Documentation
34 changes: 27 additions & 7 deletions apollo-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,34 @@ impl ShutdownSource {
match self {
ShutdownSource::None => stream::pending::<Event>().boxed(),
ShutdownSource::Custom(future) => future.map(|_| Shutdown).into_stream().boxed(),
ShutdownSource::CtrlC => async {
tokio::signal::ctrl_c()
.await
.expect("Failed to install CTRL+C signal handler");
ShutdownSource::CtrlC => {
#[cfg(not(unix))]
{
async {
tokio::signal::ctrl_c()
.await
.expect("Failed to install CTRL+C signal handler");
}
.map(|_| Shutdown)
.into_stream()
.boxed()
}

#[cfg(unix)]
future::select(
tokio::signal::ctrl_c().map(|s| s.ok()).boxed(),
async {
tokio::signal::unix::signal(tokio::signal::unix::SignalKind::terminate())
.expect("Failed to install SIGTERM signal handler")
.recv()
.await
}
.boxed(),
)
.map(|_| Shutdown)
.into_stream()
.boxed()
}
.map(|_| Shutdown)
.into_stream()
.boxed(),
}
}
}
Expand Down

0 comments on commit 89b7a96

Please sign in to comment.