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
7 changes: 7 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ Example of logs in JSON:

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

### Reload the configuration when receiving the SIGHUP signal [Issue #35](https://github.com/apollographql/router/issues/35))

This adds support for reloading configuration when receiving the SIGHUP signal. This only works on unix-like platforms,
and only with the configuration file.

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

## 🐛 Fixes

### Fix the deduplication logic in deduplication caching [Issue #1984](https://github.com/apollographql/router/issues/1984))
Expand Down
47 changes: 43 additions & 4 deletions apollo-router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,10 +318,49 @@ impl ConfigurationSource {
.boxed()
} else {
match ConfigurationSource::read_config(&path) {
Ok(configuration) => stream::once(future::ready(UpdateConfiguration(
Box::new(configuration),
)))
.boxed(),
Ok(configuration) => {
#[cfg(any(test, not(unix)))]
{
stream::once(future::ready(UpdateConfiguration(Box::new(
configuration,
))))
.boxed()
}

#[cfg(all(not(test), unix))]
{
let mut sighup_stream = tokio::signal::unix::signal(
tokio::signal::unix::SignalKind::hangup(),
)
.expect("Failed to install SIGHUP signal handler");

let (mut tx, rx) = futures::channel::mpsc::channel(1);
tokio::task::spawn(async move {
while let Some(()) = sighup_stream.recv().await {
tx.send(()).await.unwrap();
}
});
futures::stream::select(
stream::once(future::ready(UpdateConfiguration(Box::new(
configuration,
))))
.boxed(),
rx.filter_map(
move |()| match ConfigurationSource::read_config(&path) {
Ok(configuration) => future::ready(Some(
UpdateConfiguration(Box::new(configuration)),
)),
Err(err) => {
tracing::error!("{}", err);
future::ready(None)
}
},
)
.boxed(),
)
.boxed()
}
}
Err(err) => {
tracing::error!("{}", err);
stream::empty().boxed()
Expand Down