diff --git a/config.toml b/config.toml index 3b88e034a..1fb17413e 100644 --- a/config.toml +++ b/config.toml @@ -94,4 +94,4 @@ # Maximum duration given to shutdown the whole application gracefully. # # Default: -# timeout = "1s" +# timeout = "5s" diff --git a/src/api/client/server.rs b/src/api/client/server.rs index ad8761530..7f1fe7d7f 100644 --- a/src/api/client/server.rs +++ b/src/api/client/server.rs @@ -131,7 +131,7 @@ impl Handler 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)) } } diff --git a/src/shutdown.rs b/src/shutdown.rs index eaa57df1c..83091a2dc 100644 --- a/src/shutdown.rs +++ b/src/shutdown.rs @@ -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::*; @@ -132,6 +132,7 @@ impl Handler for GracefulShutdown { let by_priority: Vec<_> = self .subs .values() + .rev() .map(|addrs| { let addrs: Vec<_> = addrs .iter() @@ -147,16 +148,18 @@ impl Handler 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), ) } } diff --git a/src/signalling/room.rs b/src/signalling/room.rs index 46b52c99b..9a7217b50 100644 --- a/src/signalling/room.rs +++ b/src/signalling/room.rs @@ -467,7 +467,10 @@ impl Handler 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) } }