From 161d1ee94b5dca1e2a9cfc99d5dcd4bdcfb31072 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Sun, 7 Nov 2021 21:00:19 +0800 Subject: [PATCH] fix accept timeout and worker graceful shutdown (#412) --- actix-server/src/accept.rs | 2 +- actix-server/src/worker.rs | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/actix-server/src/accept.rs b/actix-server/src/accept.rs index bdeb6004..cd37460b 100644 --- a/actix-server/src/accept.rs +++ b/actix-server/src/accept.rs @@ -127,7 +127,7 @@ impl Accept { let mut events = mio::Events::with_capacity(256); loop { - if let Err(e) = self.poll.poll(&mut events, None) { + if let Err(e) = self.poll.poll(&mut events, self.timeout) { match e.kind() { io::ErrorKind::Interrupted => {} _ => panic!("Poll error: {}", e), diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index af14ab4b..2d104b8d 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -552,6 +552,14 @@ impl Future for ServerWorker { self.poll(cx) } WorkerState::Shutdown(ref mut shutdown) => { + // drop all pending connections in rx channel. + while let Poll::Ready(Some(conn)) = Pin::new(&mut this.rx).poll_recv(cx) { + // WorkerCounterGuard is needed as Accept thread has incremented counter. + // It's guard's job to decrement the counter together with drop of Conn. + let guard = this.counter.guard(); + drop((conn, guard)); + } + // wait for 1 second ready!(shutdown.timer.as_mut().poll(cx));