From 93889776c4235f3e0bf7669bf8e8954fb660816b Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 12 Dec 2020 17:19:20 +0000 Subject: [PATCH 1/3] prevent double registration of sockets when backpressure is resolved (#223) --- actix-server/CHANGES.md | 4 ++++ actix-server/src/accept.rs | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/actix-server/CHANGES.md b/actix-server/CHANGES.md index 5011f69c..5e28fe0b 100644 --- a/actix-server/CHANGES.md +++ b/actix-server/CHANGES.md @@ -2,6 +2,10 @@ ## Unreleased - 2020-xx-xx * Added explicit info log message on accept queue pause. [#215] +* Prevent double registration of sockets when back-pressure is resolved. [#223] + +[#215]: https://github.com/actix/actix-net/pull/215 +[#223]: https://github.com/actix/actix-net/pull/223 ## 1.0.4 - 2020-09-12 diff --git a/actix-server/src/accept.rs b/actix-server/src/accept.rs index 39da03bc..bef175d8 100644 --- a/actix-server/src/accept.rs +++ b/actix-server/src/accept.rs @@ -370,6 +370,11 @@ impl Accept { if !on { self.backpressure = false; for (token, info) in self.sockets.iter() { + if info.timeout.is_some() { + // socket will attempt to re-register itself when its timeout completes + continue; + } + if let Err(err) = self.register(token, info) { error!("Can not resume socket accept process: {}", err); } else { From 4e43216b99a4928551dddd491173de4be32c02f7 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 12 Dec 2020 23:24:00 +0000 Subject: [PATCH 2/3] standardise compiler lints across all crates (#226) --- actix-codec/src/lib.rs | 4 +++- actix-connect/src/lib.rs | 4 +++- actix-macros/src/lib.rs | 5 ++++- actix-rt/src/lib.rs | 4 +++- actix-server/src/lib.rs | 4 +++- actix-service/src/lib.rs | 4 +++- actix-testing/src/lib.rs | 5 ++++- actix-threadpool/src/lib.rs | 4 ++++ actix-tls/src/lib.rs | 4 +++- actix-tracing/src/lib.rs | 5 ++++- actix-utils/src/lib.rs | 4 +++- router/src/de.rs | 2 +- router/src/lib.rs | 4 ++++ router/src/path.rs | 2 +- string/src/lib.rs | 8 ++++++-- 15 files changed, 49 insertions(+), 14 deletions(-) diff --git a/actix-codec/src/lib.rs b/actix-codec/src/lib.rs index d972763e..07939549 100644 --- a/actix-codec/src/lib.rs +++ b/actix-codec/src/lib.rs @@ -9,8 +9,10 @@ //! [`Sink`]: futures_sink::Sink //! [`Stream`]: futures_core::Stream -#![deny(rust_2018_idioms)] +#![deny(rust_2018_idioms, nonstandard_style)] #![warn(missing_docs)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] mod bcodec; mod framed; diff --git a/actix-connect/src/lib.rs b/actix-connect/src/lib.rs index ea6d7ab8..36d0b98a 100644 --- a/actix-connect/src/lib.rs +++ b/actix-connect/src/lib.rs @@ -5,8 +5,10 @@ //! * `openssl` - enables TLS support via `openssl` crate //! * `rustls` - enables TLS support via `rustls` crate -#![deny(rust_2018_idioms)] +#![deny(rust_2018_idioms, nonstandard_style)] #![recursion_limit = "128"] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] #[macro_use] extern crate log; diff --git a/actix-macros/src/lib.rs b/actix-macros/src/lib.rs index e4baa15b..fc655a64 100644 --- a/actix-macros/src/lib.rs +++ b/actix-macros/src/lib.rs @@ -1,5 +1,8 @@ //! Macros for use with Tokio -extern crate proc_macro; + +#![deny(rust_2018_idioms, nonstandard_style)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] use proc_macro::TokenStream; use quote::quote; diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index ad76929c..dccd9202 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -1,6 +1,8 @@ //! A runtime implementation that runs everything on the current thread. -#![deny(rust_2018_idioms, warnings)] +#![deny(rust_2018_idioms, nonstandard_style)] #![allow(clippy::type_complexity)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] #[cfg(not(test))] // Work around for rust-lang/rust#62127 pub use actix_macros::{main, test}; diff --git a/actix-server/src/lib.rs b/actix-server/src/lib.rs index 8efc29d3..d7a7c242 100644 --- a/actix-server/src/lib.rs +++ b/actix-server/src/lib.rs @@ -1,6 +1,8 @@ //! General purpose TCP server. -#![deny(rust_2018_idioms)] +#![deny(rust_2018_idioms, nonstandard_style)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] mod accept; mod builder; diff --git a/actix-service/src/lib.rs b/actix-service/src/lib.rs index fd09184c..b25a6f98 100644 --- a/actix-service/src/lib.rs +++ b/actix-service/src/lib.rs @@ -1,7 +1,9 @@ //! See [`Service`](trait.Service.html) docs for information on this crate's foundational trait. -#![deny(rust_2018_idioms, warnings)] +#![deny(rust_2018_idioms, nonstandard_style)] #![allow(clippy::type_complexity)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] use std::cell::RefCell; use std::future::Future; diff --git a/actix-testing/src/lib.rs b/actix-testing/src/lib.rs index 3ec81061..efcdd394 100644 --- a/actix-testing/src/lib.rs +++ b/actix-testing/src/lib.rs @@ -1,6 +1,9 @@ //! Various helpers for Actix applications to use during testing. -#![deny(rust_2018_idioms, warnings)] + +#![deny(rust_2018_idioms, nonstandard_style)] #![allow(clippy::type_complexity, clippy::needless_doctest_main)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] use std::sync::mpsc; use std::{net, thread}; diff --git a/actix-threadpool/src/lib.rs b/actix-threadpool/src/lib.rs index 08b563ef..2fda28ef 100644 --- a/actix-threadpool/src/lib.rs +++ b/actix-threadpool/src/lib.rs @@ -1,5 +1,9 @@ //! Thread pool for blocking operations +#![deny(rust_2018_idioms, nonstandard_style)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] + use std::fmt; use std::future::Future; use std::pin::Pin; diff --git a/actix-tls/src/lib.rs b/actix-tls/src/lib.rs index 5613c5f2..8cc18046 100644 --- a/actix-tls/src/lib.rs +++ b/actix-tls/src/lib.rs @@ -5,7 +5,9 @@ //! * `rustls` - TLS acceptor using the `rustls` crate. //! * `nativetls` - TLS acceptor using the `native-tls` crate. -#![deny(rust_2018_idioms)] +#![deny(rust_2018_idioms, nonstandard_style)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] use std::sync::atomic::{AtomicUsize, Ordering}; diff --git a/actix-tracing/src/lib.rs b/actix-tracing/src/lib.rs index 35c85286..c011790b 100644 --- a/actix-tracing/src/lib.rs +++ b/actix-tracing/src/lib.rs @@ -1,5 +1,8 @@ //! Actix tracing - support for tokio tracing with Actix services. -#![deny(rust_2018_idioms, warnings)] + +#![deny(rust_2018_idioms, nonstandard_style)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] use std::marker::PhantomData; use std::task::{Context, Poll}; diff --git a/actix-utils/src/lib.rs b/actix-utils/src/lib.rs index 7fde1f59..19df225b 100644 --- a/actix-utils/src/lib.rs +++ b/actix-utils/src/lib.rs @@ -1,7 +1,9 @@ //! Actix utils - various helper services -#![deny(rust_2018_idioms)] +#![deny(rust_2018_idioms, nonstandard_style)] #![allow(clippy::type_complexity)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] pub mod condition; pub mod counter; diff --git a/router/src/de.rs b/router/src/de.rs index ce29d2af..81796348 100644 --- a/router/src/de.rs +++ b/router/src/de.rs @@ -42,7 +42,7 @@ macro_rules! parse_single_value { }; } -pub struct PathDeserializer<'de, T: ResourcePath + 'de> { +pub struct PathDeserializer<'de, T: ResourcePath> { path: &'de Path, } diff --git a/router/src/lib.rs b/router/src/lib.rs index e141d667..5850b103 100644 --- a/router/src/lib.rs +++ b/router/src/lib.rs @@ -1,5 +1,9 @@ //! Resource path matching library. +#![deny(rust_2018_idioms, nonstandard_style)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] + mod de; mod path; mod resource; diff --git a/router/src/path.rs b/router/src/path.rs index 0e13c37a..0998c614 100644 --- a/router/src/path.rs +++ b/router/src/path.rs @@ -158,7 +158,7 @@ impl Path { } /// Return iterator to items in parameter container - pub fn iter(&self) -> PathIter { + pub fn iter(&self) -> PathIter<'_, T> { PathIter { idx: 0, params: self, diff --git a/string/src/lib.rs b/string/src/lib.rs index dd89399b..553c8634 100644 --- a/string/src/lib.rs +++ b/string/src/lib.rs @@ -1,5 +1,9 @@ //! A UTF-8 encoded read-only string using Bytes as storage. +#![deny(rust_2018_idioms, nonstandard_style)] +#![doc(html_logo_url = "https://actix.rs/img/logo.png")] +#![doc(html_favicon_url = "https://actix.rs/favicon.ico")] + use std::convert::TryFrom; use std::{borrow, fmt, hash, ops, str}; @@ -156,13 +160,13 @@ macro_rules! array_impls { array_impls!(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16); impl fmt::Debug for ByteString { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(fmt) } } impl fmt::Display for ByteString { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(fmt) } } From 049795662febac074a39b838a29c263ebebb8b0a Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Sun, 13 Dec 2020 08:46:32 +0800 Subject: [PATCH 3/3] remove ServerMessage type. remove one unused InternalServiceFactory impl (#225) --- actix-server/src/config.rs | 11 ++++--- actix-server/src/service.rs | 60 +++++++++---------------------------- actix-server/src/worker.rs | 17 ++--------- 3 files changed, 22 insertions(+), 66 deletions(-) diff --git a/actix-server/src/config.rs b/actix-server/src/config.rs index fda1ade9..28996b9b 100644 --- a/actix-server/src/config.rs +++ b/actix-server/src/config.rs @@ -8,10 +8,9 @@ use futures_util::future::{ok, Future, FutureExt, LocalBoxFuture}; use log::error; use super::builder::bind_addr; -use super::service::{ - BoxedServerService, InternalServiceFactory, ServerMessage, StreamService, -}; +use super::service::{BoxedServerService, InternalServiceFactory, StreamService}; use super::Token; +use crate::socket::StdStream; pub struct ServiceConfig { pub(crate) services: Vec<(String, net::TcpListener)>, @@ -239,7 +238,7 @@ impl ServiceRuntime { type BoxedNewService = Box< dyn actix::ServiceFactory< - Request = (Option, ServerMessage), + Request = (Option, StdStream), Response = (), Error = (), InitError = (), @@ -261,12 +260,12 @@ where T::Error: 'static, T::InitError: fmt::Debug + 'static, { - type Request = (Option, ServerMessage); + type Request = (Option, StdStream); type Response = (); type Error = (); - type InitError = (); type Config = (); type Service = BoxedServerService; + type InitError = (); type Future = LocalBoxFuture<'static, Result>; fn new_service(&self, _: ()) -> Self::Future { diff --git a/actix-server/src/service.rs b/actix-server/src/service.rs index 984e5228..4fc49586 100644 --- a/actix-server/src/service.rs +++ b/actix-server/src/service.rs @@ -1,7 +1,6 @@ use std::marker::PhantomData; use std::net::SocketAddr; use std::task::{Context, Poll}; -use std::time::Duration; use actix_rt::spawn; use actix_service::{self as actix, Service, ServiceFactory as ActixServiceFactory}; @@ -13,18 +12,6 @@ use log::error; use super::Token; use crate::socket::{FromStream, StdStream}; -/// Server message -pub(crate) enum ServerMessage { - /// New stream - Connect(StdStream), - - /// Gracefully shutdown - Shutdown(Duration), - - /// Force shutdown - ForceShutdown, -} - pub trait ServiceFactory: Send + Clone + 'static { type Factory: actix::ServiceFactory; @@ -41,7 +28,7 @@ pub(crate) trait InternalServiceFactory: Send { pub(crate) type BoxedServerService = Box< dyn Service< - Request = (Option, ServerMessage), + Request = (Option, StdStream), Response = (), Error = (), Future = Ready>, @@ -65,7 +52,7 @@ where T::Error: 'static, I: FromStream, { - type Request = (Option, ServerMessage); + type Request = (Option, StdStream); type Response = (); type Error = (); type Future = Ready>; @@ -74,25 +61,20 @@ where self.service.poll_ready(ctx).map_err(|_| ()) } - fn call(&mut self, (guard, req): (Option, ServerMessage)) -> Self::Future { - match req { - ServerMessage::Connect(stream) => { - let stream = FromStream::from_stdstream(stream).map_err(|e| { - error!("Can not convert to an async tcp stream: {}", e); + fn call(&mut self, (guard, req): (Option, StdStream)) -> Self::Future { + match FromStream::from_stdstream(req) { + Ok(stream) => { + let f = self.service.call(stream); + spawn(async move { + let _ = f.await; + drop(guard); }); - - if let Ok(stream) = stream { - let f = self.service.call(stream); - spawn(async move { - let _ = f.await; - drop(guard); - }); - ok(()) - } else { - err(()) - } + ok(()) + } + Err(e) => { + error!("Can not convert to an async tcp stream: {}", e); + err(()) } - _ => ok(()), } } } @@ -159,20 +141,6 @@ where } } -impl InternalServiceFactory for Box { - fn name(&self, token: Token) -> &str { - self.as_ref().name(token) - } - - fn clone_factory(&self) -> Box { - self.as_ref().clone_factory() - } - - fn create(&self) -> LocalBoxFuture<'static, Result, ()>> { - self.as_ref().create() - } -} - impl ServiceFactory for F where F: Fn() -> T + Send + Clone + 'static, diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index 35331757..bfd11979 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -14,7 +14,7 @@ use futures_util::{future::Future, stream::Stream, FutureExt, TryFutureExt}; use log::{error, info, trace}; use crate::accept::AcceptNotify; -use crate::service::{BoxedServerService, InternalServiceFactory, ServerMessage}; +use crate::service::{BoxedServerService, InternalServiceFactory}; use crate::socket::{SocketAddr, StdStream}; use crate::Token; @@ -228,23 +228,12 @@ impl Worker { self.services.iter_mut().for_each(|srv| { if srv.status == WorkerServiceStatus::Available { srv.status = WorkerServiceStatus::Stopped; - actix_rt::spawn( - srv.service - .call((None, ServerMessage::ForceShutdown)) - .map(|_| ()), - ); } }); } else { - let timeout = self.shutdown_timeout; self.services.iter_mut().for_each(move |srv| { if srv.status == WorkerServiceStatus::Available { srv.status = WorkerServiceStatus::Stopping; - actix_rt::spawn( - srv.service - .call((None, ServerMessage::Shutdown(timeout))) - .map(|_| ()), - ); } }); } @@ -361,7 +350,7 @@ impl Future for Worker { let guard = self.conns.get(); let _ = self.services[conn.token.0] .service - .call((Some(guard), ServerMessage::Connect(conn.io))); + .call((Some(guard), conn.io)); } else { self.state = WorkerState::Available; self.availability.set(true); @@ -455,7 +444,7 @@ impl Future for Worker { let guard = self.conns.get(); let _ = self.services[msg.token.0] .service - .call((Some(guard), ServerMessage::Connect(msg.io))); + .call((Some(guard), msg.io)); continue; } Ok(false) => {