From 3e3d3279b8e395c41f108867f93d0a7cc42ca148 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 16 Feb 2018 09:42:15 -0800 Subject: [PATCH] deregister server socket on shutdown --- examples/r2d2/src/main.rs | 1 + src/server/srv.rs | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/examples/r2d2/src/main.rs b/examples/r2d2/src/main.rs index 2efc64b9..4c6ebfc9 100644 --- a/examples/r2d2/src/main.rs +++ b/examples/r2d2/src/main.rs @@ -44,6 +44,7 @@ fn main() { let _ = env_logger::init(); let sys = actix::System::new("r2d2-example"); + // r2d2 pool let manager = SqliteConnectionManager::file("test.db"); let pool = r2d2::Pool::new(manager).unwrap(); diff --git a/src/server/srv.rs b/src/server/srv.rs index 4f1d5c20..63f23d24 100644 --- a/src/server/srv.rs +++ b/src/server/srv.rs @@ -666,11 +666,21 @@ fn start_accept_thread(sock: net::TcpListener, addr: net::SocketAddr, backlog: i } } }, - Command::Stop => return, + Command::Stop => { + if let Some(server) = server.take() { + let _ = poll.deregister(&server); + } + return + }, }, Err(err) => match err { sync_mpsc::TryRecvError::Empty => (), - sync_mpsc::TryRecvError::Disconnected => return, + sync_mpsc::TryRecvError::Disconnected => { + if let Some(server) = server.take() { + let _ = poll.deregister(&server); + } + return + }, } }, _ => unreachable!(),