From 7749dfe46a5af18122e02a7d64bf74699d080c5b Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Fri, 16 Apr 2021 02:06:11 +0100 Subject: [PATCH 1/8] address msrv todo in router --- actix-codec/src/lib.rs | 2 +- actix-router/src/resource.rs | 5 +---- actix-service/src/lib.rs | 2 +- actix-tls/src/connect/resolve.rs | 2 +- 4 files changed, 4 insertions(+), 7 deletions(-) diff --git a/actix-codec/src/lib.rs b/actix-codec/src/lib.rs index dec30ba6..c7713bfe 100644 --- a/actix-codec/src/lib.rs +++ b/actix-codec/src/lib.rs @@ -7,7 +7,7 @@ //! [`Sink`]: futures_sink::Sink //! [`Stream`]: futures_core::Stream -#![deny(rust_2018_idioms, nonstandard_style)] +#![deny(rust_2018_idioms, nonstandard_style, future_incompatible)] #![warn(missing_docs)] #![doc(html_logo_url = "https://actix.rs/img/logo.png")] #![doc(html_favicon_url = "https://actix.rs/favicon.ico")] diff --git a/actix-router/src/resource.rs b/actix-router/src/resource.rs index 98b4a709..32162c53 100644 --- a/actix-router/src/resource.rs +++ b/actix-router/src/resource.rs @@ -581,10 +581,7 @@ impl ResourceDef { mut for_prefix: bool, ) -> (String, Vec, bool, usize) { if pattern.find('{').is_none() { - // TODO: MSRV: 1.45 - #[allow(clippy::manual_strip)] - return if pattern.ends_with('*') { - let path = &pattern[..pattern.len() - 1]; + return if let Some(path) = pattern.strip_suffix('*') { let re = String::from("^") + path + "(.*)"; (re, vec![PatternElement::Str(String::from(path))], true, 0) } else { diff --git a/actix-service/src/lib.rs b/actix-service/src/lib.rs index 8f839121..e26d5c62 100644 --- a/actix-service/src/lib.rs +++ b/actix-service/src/lib.rs @@ -1,7 +1,7 @@ //! See [`Service`] docs for information on this crate's foundational trait. #![no_std] -#![deny(rust_2018_idioms, nonstandard_style)] +#![deny(rust_2018_idioms, nonstandard_style, future_incompatible)] #![warn(missing_docs)] #![allow(clippy::type_complexity)] #![doc(html_logo_url = "https://actix.rs/img/logo.png")] diff --git a/actix-tls/src/connect/resolve.rs b/actix-tls/src/connect/resolve.rs index 32e442bf..0a92b9b1 100755 --- a/actix-tls/src/connect/resolve.rs +++ b/actix-tls/src/connect/resolve.rs @@ -56,7 +56,7 @@ pub enum Resolver { /// An interface for custom async DNS resolvers. /// /// # Usage -/// ```rust +/// ``` /// use std::net::SocketAddr; /// /// use actix_tls::connect::{Resolve, Resolver}; From fdafc1dd655c43b126b2e0eb61761098240e9f44 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Fri, 16 Apr 2021 02:08:44 +0100 Subject: [PATCH 2/8] amend licences --- LICENSE-APACHE | 2 +- LICENSE-MIT | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE-APACHE b/LICENSE-APACHE index 6cdf2d16..8f5ba39b 100644 --- a/LICENSE-APACHE +++ b/LICENSE-APACHE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2017-NOW Nikolay Kim + Copyright 2017-NOW Actix Team Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/LICENSE-MIT b/LICENSE-MIT index 0f80296a..d559b1cd 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -1,4 +1,4 @@ -Copyright (c) 2017 Nikolay Kim +Copyright (c) 2017-NOW Actix Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated From 20c2da17ed9679d7719d605ce5bc029c4a6fd713 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Thu, 15 Apr 2021 19:20:02 -0700 Subject: [PATCH 3/8] Fix worker_avail (#336) Co-authored-by: Rob Ede --- actix-server/src/accept.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/actix-server/src/accept.rs b/actix-server/src/accept.rs index 026bcc37..5b152fb2 100644 --- a/actix-server/src/accept.rs +++ b/actix-server/src/accept.rs @@ -116,14 +116,11 @@ impl Availability { panic!("Max WorkerHandle count is 512") }; + let off = 1 << idx as u128; if avail { - self.0[offset] |= 1 << idx as u128; + self.0[offset] |= off; } else { - let shift = 1 << idx as u128; - - debug_assert_ne!(self.0[offset] & shift, 0); - - self.0[offset] ^= shift; + self.0[offset] &= !off } } @@ -527,6 +524,9 @@ mod test { aval.set_available(idx, false); assert!(!aval.available()); + + aval.set_available(idx, false); + assert!(!aval.available()); } fn multi(aval: &mut Availability, mut idx: Vec) { @@ -565,13 +565,6 @@ mod test { single(&mut aval, 512); } - #[test] - #[should_panic] - fn double_set_unavailable() { - let mut aval = Availability::default(); - aval.set_available(233, false); - } - #[test] fn pin_point() { let mut aval = Availability::default(); From bd48908792c57f8d55ca20d058803fcf7e7d234d Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Thu, 15 Apr 2021 21:59:10 -0700 Subject: [PATCH 4/8] Return worker index in WakerInterest::WorkerAvailable (#337) --- actix-server/src/accept.rs | 5 ++--- actix-server/src/builder.rs | 2 +- actix-server/src/waker_queue.rs | 2 +- actix-server/src/worker.rs | 6 ++++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/actix-server/src/accept.rs b/actix-server/src/accept.rs index 5b152fb2..dbf66b20 100644 --- a/actix-server/src/accept.rs +++ b/actix-server/src/accept.rs @@ -238,11 +238,10 @@ impl Accept { match guard.pop_front() { // worker notify it becomes available. we may want to recover // from backpressure. - Some(WakerInterest::WorkerAvailable) => { + Some(WakerInterest::WorkerAvailable(idx)) => { drop(guard); - // Assume all worker are avail as no worker index returned. - self.avail.set_available_all(&self.handles); self.maybe_backpressure(&mut sockets, false); + self.avail.set_available(idx, true); } // a new worker thread is made and it's handle would be added to Accept Some(WakerInterest::Worker(handle)) => { diff --git a/actix-server/src/builder.rs b/actix-server/src/builder.rs index aa18bb22..66aba10c 100644 --- a/actix-server/src/builder.rs +++ b/actix-server/src/builder.rs @@ -320,7 +320,7 @@ impl ServerBuilder { idx: usize, waker: WakerQueue, ) -> (WorkerHandleAccept, WorkerHandleServer) { - let avail = WorkerAvailability::new(waker); + let avail = WorkerAvailability::new(idx, waker); let services = self.services.iter().map(|v| v.clone_factory()).collect(); ServerWorker::start(idx, services, avail, self.worker_config) diff --git a/actix-server/src/waker_queue.rs b/actix-server/src/waker_queue.rs index 8aa493aa..3f8669d4 100644 --- a/actix-server/src/waker_queue.rs +++ b/actix-server/src/waker_queue.rs @@ -72,7 +72,7 @@ impl WakerQueue { pub(crate) enum WakerInterest { /// `WorkerAvailable` is an interest from `Worker` notifying `Accept` there is a worker /// available and can accept new tasks. - WorkerAvailable, + WorkerAvailable(usize), /// `Pause`, `Resume`, `Stop` Interest are from `ServerBuilder` future. It listens to /// `ServerCommand` and notify `Accept` to do exactly these tasks. Pause, diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index 65951345..3d499382 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -96,13 +96,15 @@ impl WorkerHandleServer { #[derive(Clone)] pub(crate) struct WorkerAvailability { + idx: usize, waker: WakerQueue, available: Arc, } impl WorkerAvailability { - pub fn new(waker: WakerQueue) -> Self { + pub fn new(idx: usize, waker: WakerQueue) -> Self { WorkerAvailability { + idx, waker, available: Arc::new(AtomicBool::new(false)), } @@ -116,7 +118,7 @@ impl WorkerAvailability { let old = self.available.swap(val, Ordering::Release); // notify the accept on switched to available. if !old && val { - self.waker.wake(WakerInterest::WorkerAvailable); + self.waker.wake(WakerInterest::WorkerAvailable(self.idx)); } } } From 19468feef8b0fb4be1b5e4bd0e799a4d7b55a966 Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Fri, 16 Apr 2021 03:20:08 -0700 Subject: [PATCH 5/8] Fix memory ordering of WorkerAvailability (#340) --- actix-server/src/accept.rs | 8 ++++---- actix-server/src/worker.rs | 27 +++++++++++++++++++-------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/actix-server/src/accept.rs b/actix-server/src/accept.rs index dbf66b20..23ba616c 100644 --- a/actix-server/src/accept.rs +++ b/actix-server/src/accept.rs @@ -128,7 +128,7 @@ impl Availability { /// This would result in a re-check on all workers' availability. fn set_available_all(&mut self, handles: &[WorkerHandleAccept]) { handles.iter().for_each(|handle| { - self.set_available(handle.idx, true); + self.set_available(handle.idx(), true); }) } } @@ -248,7 +248,7 @@ impl Accept { drop(guard); // maybe we want to recover from a backpressure. self.maybe_backpressure(&mut sockets, false); - self.avail.set_available(handle.idx, true); + self.avail.set_available(handle.idx(), true); self.handles.push(handle); } // got timer interest and it's time to try register socket(s) again @@ -400,7 +400,7 @@ impl Accept { } else { while self.avail.available() { let next = self.next(); - let idx = next.idx; + let idx = next.idx(); if next.available() { self.avail.set_available(idx, true); match self.send_connection(sockets, conn) { @@ -503,7 +503,7 @@ impl Accept { /// Remove next worker handle that fail to accept connection. fn remove_next(&mut self) { let handle = self.handles.swap_remove(self.next); - let idx = handle.idx; + let idx = handle.idx(); // A message is sent to `ServerBuilder` future to notify it a new worker // should be made. self.srv.worker_faulted(idx); diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index 3d499382..7bc211b1 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -47,11 +47,7 @@ fn handle_pair( tx2: UnboundedSender, avail: WorkerAvailability, ) -> (WorkerHandleAccept, WorkerHandleServer) { - let accept = WorkerHandleAccept { - idx, - tx: tx1, - avail, - }; + let accept = WorkerHandleAccept { tx: tx1, avail }; let server = WorkerHandleServer { idx, tx: tx2 }; @@ -63,16 +59,22 @@ fn handle_pair( /// /// Held by [Accept](crate::accept::Accept). pub(crate) struct WorkerHandleAccept { - pub idx: usize, tx: UnboundedSender, avail: WorkerAvailability, } impl WorkerHandleAccept { + #[inline(always)] + pub(crate) fn idx(&self) -> usize { + self.avail.idx + } + + #[inline(always)] pub(crate) fn send(&self, msg: Conn) -> Result<(), Conn> { self.tx.send(msg).map_err(|msg| msg.0) } + #[inline(always)] pub(crate) fn available(&self) -> bool { self.avail.available() } @@ -110,13 +112,18 @@ impl WorkerAvailability { } } + #[inline(always)] pub fn available(&self) -> bool { self.available.load(Ordering::Acquire) } pub fn set(&self, val: bool) { - let old = self.available.swap(val, Ordering::Release); - // notify the accept on switched to available. + // Ordering: + // + // There could be multiple set calls happen in one ::poll. + // Order is important between them. + let old = self.available.swap(val, Ordering::AcqRel); + // Notify the accept on switched to available. if !old && val { self.waker.wake(WakerInterest::WorkerAvailable(self.idx)); } @@ -374,6 +381,10 @@ impl Default for WorkerState { impl Drop for ServerWorker { fn drop(&mut self) { + // Set availability to true so if accept try to send connection to this worker + // it would find worker is gone and remove it. + // This is helpful when worker is dropped unexpected. + self.availability.set(true); // Stop the Arbiter ServerWorker runs on on drop. Arbiter::current().stop(); } From 2435520e6713c197227d21be8828e5354aa956fb Mon Sep 17 00:00:00 2001 From: fakeshadow <24548779@qq.com> Date: Fri, 16 Apr 2021 06:40:21 -0700 Subject: [PATCH 6/8] Remove/restart worker test (#341) --- actix-server/tests/test_server.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/actix-server/tests/test_server.rs b/actix-server/tests/test_server.rs index 3af072bb..cc9f8190 100644 --- a/actix-server/tests/test_server.rs +++ b/actix-server/tests/test_server.rs @@ -437,6 +437,7 @@ async fn test_service_restart() { let _ = h.join().unwrap(); } +#[ignore] #[actix_rt::test] async fn worker_restart() { use actix_service::{Service, ServiceFactory}; From 1c4e96536637cde59110e298b322c5332f4caeba Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Fri, 16 Apr 2021 15:18:53 +0100 Subject: [PATCH 7/8] prepare service release 2.0.0 (#339) --- actix-server/Cargo.toml | 2 +- actix-service/CHANGES.md | 3 +++ actix-service/Cargo.toml | 7 ++----- actix-service/README.md | 4 ++-- actix-tls/Cargo.toml | 2 +- actix-tracing/Cargo.toml | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/actix-server/Cargo.toml b/actix-server/Cargo.toml index 80b44c6d..a839dddb 100755 --- a/actix-server/Cargo.toml +++ b/actix-server/Cargo.toml @@ -22,7 +22,7 @@ default = [] [dependencies] actix-rt = { version = "2.0.0", default-features = false } -actix-service = "2.0.0-beta.5" +actix-service = "2.0.0" actix-utils = "3.0.0-beta.4" futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] } diff --git a/actix-service/CHANGES.md b/actix-service/CHANGES.md index c99cc2eb..a0130dbc 100644 --- a/actix-service/CHANGES.md +++ b/actix-service/CHANGES.md @@ -1,6 +1,9 @@ # Changes ## Unreleased - 2021-xx-xx + + +## 2.0.0 - 2021-04-16 * Removed pipeline and related structs/functions. [#335] [#335]: https://github.com/actix/actix-net/pull/335 diff --git a/actix-service/Cargo.toml b/actix-service/Cargo.toml index 1c82f703..ad03242f 100644 --- a/actix-service/Cargo.toml +++ b/actix-service/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-service" -version = "2.0.0-beta.5" +version = "2.0.0" authors = [ "Nikolay Kim ", "Rob Ede ", @@ -8,10 +8,7 @@ authors = [ ] description = "Service trait and combinators for representing asynchronous request/response operations." keywords = ["network", "framework", "async", "futures", "service"] -homepage = "https://actix.rs" -repository = "https://github.com/actix/actix-net.git" -documentation = "https://docs.rs/actix-service" -readme = "README.md" +repository = "https://github.com/actix/actix-net" categories = ["network-programming", "asynchronous"] license = "MIT OR Apache-2.0" edition = "2018" diff --git a/actix-service/README.md b/actix-service/README.md index 54171274..913ac199 100644 --- a/actix-service/README.md +++ b/actix-service/README.md @@ -3,10 +3,10 @@ > Service trait and combinators for representing asynchronous request/response operations. [![crates.io](https://img.shields.io/crates/v/actix-service?label=latest)](https://crates.io/crates/actix-service) -[![Documentation](https://docs.rs/actix-service/badge.svg?version=2.0.0-beta.5)](https://docs.rs/actix-service/2.0.0-beta.5) +[![Documentation](https://docs.rs/actix-service/badge.svg?version=2.0.0)](https://docs.rs/actix-service/2.0.0) [![Version](https://img.shields.io/badge/rustc-1.46+-ab6000.svg)](https://blog.rust-lang.org/2020/03/12/Rust-1.46.html) ![License](https://img.shields.io/crates/l/actix-service.svg) -[![Dependency Status](https://deps.rs/crate/actix-service/2.0.0-beta.5/status.svg)](https://deps.rs/crate/actix-service/2.0.0-beta.5) +[![Dependency Status](https://deps.rs/crate/actix-service/2.0.0/status.svg)](https://deps.rs/crate/actix-service/2.0.0) ![Download](https://img.shields.io/crates/d/actix-service.svg) [![Chat on Discord](https://img.shields.io/discord/771444961383153695?label=chat&logo=discord)](https://discord.gg/NWpN5mmg3x) diff --git a/actix-tls/Cargo.toml b/actix-tls/Cargo.toml index 7fbd94b0..4e047cf5 100755 --- a/actix-tls/Cargo.toml +++ b/actix-tls/Cargo.toml @@ -42,7 +42,7 @@ uri = ["http"] [dependencies] actix-codec = "0.4.0-beta.1" actix-rt = { version = "2.2.0", default-features = false } -actix-service = "2.0.0-beta.5" +actix-service = "2.0.0" actix-utils = "3.0.0-beta.4" derive_more = "0.99.5" diff --git a/actix-tracing/Cargo.toml b/actix-tracing/Cargo.toml index ec2e4a7c..46cdc278 100644 --- a/actix-tracing/Cargo.toml +++ b/actix-tracing/Cargo.toml @@ -16,7 +16,7 @@ name = "actix_tracing" path = "src/lib.rs" [dependencies] -actix-service = "2.0.0-beta.5" +actix-service = "2.0.0" actix-utils = "3.0.0-beta.4" tracing = "0.1" From 978e4f25fb0078e02165c11784fa2694b72ed57a Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 17 Apr 2021 02:00:36 +0100 Subject: [PATCH 8/8] prepare actix-utils release 3.0.0 (#342) --- actix-server/Cargo.toml | 2 +- actix-service/Cargo.toml | 4 ++-- actix-tls/Cargo.toml | 2 +- actix-tracing/Cargo.toml | 2 +- actix-utils/CHANGES.md | 4 ++++ actix-utils/Cargo.toml | 6 +++--- actix-utils/src/lib.rs | 2 +- 7 files changed, 13 insertions(+), 9 deletions(-) diff --git a/actix-server/Cargo.toml b/actix-server/Cargo.toml index a839dddb..a1cf520a 100755 --- a/actix-server/Cargo.toml +++ b/actix-server/Cargo.toml @@ -23,7 +23,7 @@ default = [] [dependencies] actix-rt = { version = "2.0.0", default-features = false } actix-service = "2.0.0" -actix-utils = "3.0.0-beta.4" +actix-utils = "3.0.0" futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] } log = "0.4" diff --git a/actix-service/Cargo.toml b/actix-service/Cargo.toml index ad03242f..7865cd86 100644 --- a/actix-service/Cargo.toml +++ b/actix-service/Cargo.toml @@ -8,8 +8,8 @@ authors = [ ] description = "Service trait and combinators for representing asynchronous request/response operations." keywords = ["network", "framework", "async", "futures", "service"] -repository = "https://github.com/actix/actix-net" categories = ["network-programming", "asynchronous"] +repository = "https://github.com/actix/actix-net" license = "MIT OR Apache-2.0" edition = "2018" @@ -24,5 +24,5 @@ pin-project-lite = "0.2" [dev-dependencies] actix-rt = "2.0.0" -actix-utils = "3.0.0-beta.4" +actix-utils = "3.0.0" futures-util = { version = "0.3.7", default-features = false } diff --git a/actix-tls/Cargo.toml b/actix-tls/Cargo.toml index 4e047cf5..73395a14 100755 --- a/actix-tls/Cargo.toml +++ b/actix-tls/Cargo.toml @@ -43,7 +43,7 @@ uri = ["http"] actix-codec = "0.4.0-beta.1" actix-rt = { version = "2.2.0", default-features = false } actix-service = "2.0.0" -actix-utils = "3.0.0-beta.4" +actix-utils = "3.0.0" derive_more = "0.99.5" futures-core = { version = "0.3.7", default-features = false, features = ["alloc"] } diff --git a/actix-tracing/Cargo.toml b/actix-tracing/Cargo.toml index 46cdc278..2ed2c434 100644 --- a/actix-tracing/Cargo.toml +++ b/actix-tracing/Cargo.toml @@ -17,7 +17,7 @@ path = "src/lib.rs" [dependencies] actix-service = "2.0.0" -actix-utils = "3.0.0-beta.4" +actix-utils = "3.0.0" tracing = "0.1" tracing-futures = "0.2" diff --git a/actix-utils/CHANGES.md b/actix-utils/CHANGES.md index d14446de..79f171b4 100644 --- a/actix-utils/CHANGES.md +++ b/actix-utils/CHANGES.md @@ -3,6 +3,10 @@ ## Unreleased - 2021-xx-xx +## 3.0.0 - 2021-04-16 +* No significant changes from `3.0.0-beta.4`. + + ## 3.0.0-beta.4 - 2021-04-01 * Add `future::Either` type. [#305] diff --git a/actix-utils/Cargo.toml b/actix-utils/Cargo.toml index 8b593697..a94706a2 100644 --- a/actix-utils/Cargo.toml +++ b/actix-utils/Cargo.toml @@ -1,14 +1,14 @@ [package] name = "actix-utils" -version = "3.0.0-beta.4" +version = "3.0.0" authors = [ "Nikolay Kim ", "Rob Ede ", ] -description = "Utilities for the Actix ecosystem" +description = "Various utilities used in the Actix ecosystem" keywords = ["network", "framework", "async", "futures"] -repository = "https://github.com/actix/actix-net.git" categories = ["network-programming", "asynchronous"] +repository = "https://github.com/actix/actix-net" license = "MIT OR Apache-2.0" edition = "2018" diff --git a/actix-utils/src/lib.rs b/actix-utils/src/lib.rs index f94147ec..6d431d52 100644 --- a/actix-utils/src/lib.rs +++ b/actix-utils/src/lib.rs @@ -1,4 +1,4 @@ -//! Various utilities for the Actix ecosystem. +//! Various utilities used in the Actix ecosystem. #![deny(rust_2018_idioms, nonstandard_style)] #![warn(missing_docs)]