Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Fix GracefulShutdown (#37, 29)
Browse files Browse the repository at this point in the history
- fix OsSignal handler not sending message to subscribers
- specify correct 'shutdown.timeout' in config.toml
  • Loading branch information
alexlapa authored Jul 18, 2019
1 parent 9fa4b5b commit c02e701
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@
# Maximum duration given to shutdown the whole application gracefully.
#
# Default:
# timeout = "1s"
# timeout = "5s"
2 changes: 1 addition & 1 deletion src/api/client/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Handler<ShutdownGracefully> for Server {
_: ShutdownGracefully,
_: &mut Self::Context,
) -> Self::Result {
info!("Shutting down Client API HTTP server");
info!("Server received ShutdownGracefully message so shutting down");
Box::new(self.0.stop(true).into_actor(self))
}
}
Expand Down
27 changes: 15 additions & 12 deletions src/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use actix::{
WrapFuture as _,
};
use failure::Fail;
use futures::{future, stream, Future, Stream};
use tokio::{timer::timeout, util::FutureExt as _};
use futures::{future, stream::iter_ok, Future, Stream};
use tokio::util::FutureExt as _;

use crate::log::prelude::*;

Expand Down Expand Up @@ -132,6 +132,7 @@ impl Handler<OsSignal> for GracefulShutdown {
let by_priority: Vec<_> = self
.subs
.values()
.rev()
.map(|addrs| {
let addrs: Vec<_> = addrs
.iter()
Expand All @@ -147,16 +148,18 @@ impl Handler<OsSignal> for GracefulShutdown {
.collect();

Box::new(
stream::unfold(by_priority, |mut v| {
v.pop().map(|fut| Ok((fut, v)))
})
.collect()
.timeout(self.timeout)
.map_err(|e: timeout::Error<()>| {
error!("Graceful shutdown has timed out: {:?}", e)
})
.map(|_| System::current().stop())
.into_actor(self),
iter_ok::<_, ()>(by_priority)
.for_each(|row| row.map(|_| ()))
.timeout(self.timeout)
.map_err(|_| {
error!("Graceful shutdown has timed out, stopping system");
System::current().stop()
})
.map(|_| {
info!("Graceful shutdown succeeded, stopping system");
System::current().stop()
})
.into_actor(self),
)
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/signalling/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ impl Handler<ShutdownGracefully> for Room {
_: ShutdownGracefully,
ctx: &mut Self::Context,
) -> Self::Result {
info!("Shutdown signal received for Room: {:?}", self.id);
info!(
"Room: {:?} received ShutdownGracefully message so shutting down",
self.id
);
self.close_gracefully(ctx)
}
}
Expand Down

0 comments on commit c02e701

Please sign in to comment.