From a2662b928bda6c79110d04b73db048ea530be5e7 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Fri, 10 Jul 2020 14:55:56 +0100 Subject: [PATCH 1/6] Update PULL_REQUEST_TEMPLATE.md --- .github/PULL_REQUEST_TEMPLATE.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6426eab65..cc34e2bc6 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,12 +1,8 @@ ## PR Type What kind of change does this PR make? - - -- [ ] Bug fix -- [ ] Feature -- [ ] Refactor / code style change (no functional or public API changes) -- [ ] Other + +INSERT_PR_TYPE ## PR Checklist From e10eb648d94ad2b4edaef648847360be42d51b82 Mon Sep 17 00:00:00 2001 From: Patrick Tescher Date: Fri, 10 Jul 2020 14:35:22 -0700 Subject: [PATCH 2/6] Fix leaks with actix_http's client (#1580) --- actix-http/CHANGES.md | 1 + actix-http/src/client/pool.rs | 117 ++++++++++++++++++---------------- awc/src/request.rs | 28 ++++---- benches/server.rs | 7 +- 4 files changed, 81 insertions(+), 72 deletions(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index d18af162d..138210f95 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -7,6 +7,7 @@ * Migrate cookie handling to `cookie` crate. * Update `sha-1` to 0.9 * MSRV is now 1.41.1 +* Fix client leak [#1580] ## [2.0.0-alpha.4] - 2020-05-21 diff --git a/actix-http/src/client/pool.rs b/actix-http/src/client/pool.rs index 5a10725b0..3ce443794 100644 --- a/actix-http/src/client/pool.rs +++ b/actix-http/src/client/pool.rs @@ -2,7 +2,7 @@ use std::cell::RefCell; use std::collections::VecDeque; use std::future::Future; use std::pin::Pin; -use std::rc::Rc; +use std::rc::{Rc, Weak}; use std::task::{Context, Poll}; use std::time::{Duration, Instant}; @@ -53,16 +53,25 @@ where + 'static, { pub(crate) fn new(connector: T, config: ConnectorConfig) -> Self { + let connector_rc = Rc::new(RefCell::new(connector)); + let inner_rc = Rc::new(RefCell::new(Inner { + config, + acquired: 0, + waiters: Slab::new(), + waiters_queue: IndexSet::new(), + available: FxHashMap::default(), + waker: LocalWaker::new(), + })); + + // start support future + actix_rt::spawn(ConnectorPoolSupport { + connector: connector_rc.clone(), + inner: Rc::downgrade(&inner_rc), + }); + ConnectionPool( - Rc::new(RefCell::new(connector)), - Rc::new(RefCell::new(Inner { - config, - acquired: 0, - waiters: Slab::new(), - waiters_queue: IndexSet::new(), - available: FxHashMap::default(), - waker: LocalWaker::new(), - })), + connector_rc, + inner_rc, ) } } @@ -92,12 +101,6 @@ where } fn call(&mut self, req: Connect) -> Self::Future { - // start support future - actix_rt::spawn(ConnectorPoolSupport { - connector: self.0.clone(), - inner: self.1.clone(), - }); - let mut connector = self.0.clone(); let inner = self.1.clone(); @@ -421,7 +424,7 @@ where Io: AsyncRead + AsyncWrite + Unpin + 'static, { connector: T, - inner: Rc>>, + inner: Weak>>, } impl Future for ConnectorPoolSupport @@ -435,51 +438,55 @@ where fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let this = self.project(); - let mut inner = this.inner.as_ref().borrow_mut(); - inner.waker.register(cx.waker()); + if let Some(this_inner) = this.inner.upgrade() { + let mut inner = this_inner.as_ref().borrow_mut(); + inner.waker.register(cx.waker()); - // check waiters - loop { - let (key, token) = { - if let Some((key, token)) = inner.waiters_queue.get_index(0) { - (key.clone(), *token) - } else { - break; + // check waiters + loop { + let (key, token) = { + if let Some((key, token)) = inner.waiters_queue.get_index(0) { + (key.clone(), *token) + } else { + break; + } + }; + if inner.waiters.get(token).unwrap().is_none() { + continue; } - }; - if inner.waiters.get(token).unwrap().is_none() { - continue; - } - match inner.acquire(&key, cx) { - Acquire::NotAvailable => break, - Acquire::Acquired(io, created) => { - let tx = inner.waiters.get_mut(token).unwrap().take().unwrap().1; - if let Err(conn) = tx.send(Ok(IoConnection::new( - io, - created, - Some(Acquired(key.clone(), Some(this.inner.clone()))), - ))) { - let (io, created) = conn.unwrap().into_inner(); - inner.release_conn(&key, io, created); + match inner.acquire(&key, cx) { + Acquire::NotAvailable => break, + Acquire::Acquired(io, created) => { + let tx = inner.waiters.get_mut(token).unwrap().take().unwrap().1; + if let Err(conn) = tx.send(Ok(IoConnection::new( + io, + created, + Some(Acquired(key.clone(), Some(this_inner.clone()))), + ))) { + let (io, created) = conn.unwrap().into_inner(); + inner.release_conn(&key, io, created); + } + } + Acquire::Available => { + let (connect, tx) = + inner.waiters.get_mut(token).unwrap().take().unwrap(); + OpenWaitingConnection::spawn( + key.clone(), + tx, + this_inner.clone(), + this.connector.call(connect), + inner.config.clone(), + ); } } - Acquire::Available => { - let (connect, tx) = - inner.waiters.get_mut(token).unwrap().take().unwrap(); - OpenWaitingConnection::spawn( - key.clone(), - tx, - this.inner.clone(), - this.connector.call(connect), - inner.config.clone(), - ); - } + let _ = inner.waiters_queue.swap_remove_index(0); } - let _ = inner.waiters_queue.swap_remove_index(0); - } - Poll::Pending + Poll::Pending + } else { + Poll::Ready(()) + } } } diff --git a/awc/src/request.rs b/awc/src/request.rs index 3dd8cb2ce..c34a8e221 100644 --- a/awc/src/request.rs +++ b/awc/src/request.rs @@ -586,16 +586,16 @@ mod tests { use super::*; use crate::Client; - #[test] - fn test_debug() { + #[actix_rt::test] + async fn test_debug() { let request = Client::new().get("/").header("x-test", "111"); let repr = format!("{:?}", request); assert!(repr.contains("ClientRequest")); assert!(repr.contains("x-test")); } - #[test] - fn test_basics() { + #[actix_rt::test] + async fn test_basics() { let mut req = Client::new() .put("/") .version(Version::HTTP_2) @@ -621,8 +621,8 @@ mod tests { let _ = req.send_body(""); } - #[test] - fn test_client_header() { + #[actix_rt::test] + async fn test_client_header() { let req = Client::build() .header(header::CONTENT_TYPE, "111") .finish() @@ -639,8 +639,8 @@ mod tests { ); } - #[test] - fn test_client_header_override() { + #[actix_rt::test] + async fn test_client_header_override() { let req = Client::build() .header(header::CONTENT_TYPE, "111") .finish() @@ -658,8 +658,8 @@ mod tests { ); } - #[test] - fn client_basic_auth() { + #[actix_rt::test] + async fn client_basic_auth() { let req = Client::new() .get("/") .basic_auth("username", Some("password")); @@ -685,8 +685,8 @@ mod tests { ); } - #[test] - fn client_bearer_auth() { + #[actix_rt::test] + async fn client_bearer_auth() { let req = Client::new().get("/").bearer_auth("someS3cr3tAutht0k3n"); assert_eq!( req.head @@ -699,8 +699,8 @@ mod tests { ); } - #[test] - fn client_query() { + #[actix_rt::test] + async fn client_query() { let req = Client::new() .get("/") .query(&[("key1", "val1"), ("key2", "val2")]) diff --git a/benches/server.rs b/benches/server.rs index 70531adf7..041d0fa57 100644 --- a/benches/server.rs +++ b/benches/server.rs @@ -27,15 +27,16 @@ const STR: &str = "Hello World Hello World Hello World Hello World Hello World \ // benchmark sending all requests at the same time fn bench_async_burst(c: &mut Criterion) { + // We are using System here, since Runtime requires preinitialized tokio + // Maybe add to actix_rt docs + let mut rt = actix_rt::System::new("test"); + let srv = test::start(|| { App::new() .service(web::resource("/").route(web::to(|| HttpResponse::Ok().body(STR)))) }); - // We are using System here, since Runtime requires preinitialized tokio - // Maybe add to actix_rt docs let url = srv.url("/"); - let mut rt = actix_rt::System::new("test"); c.bench_function("get_body_async_burst", move |b| { b.iter_custom(|iters| { From 327e472e440c98815c4705c2dcec0e1f9ffaac18 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Mon, 13 Jul 2020 15:35:30 +0100 Subject: [PATCH 3/6] prepare http-2.0.0-beta.1 release (#1596) --- actix-http/CHANGES.md | 16 +++++++++++----- actix-http/Cargo.toml | 4 ++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/actix-http/CHANGES.md b/actix-http/CHANGES.md index 138210f95..a185a9f81 100644 --- a/actix-http/CHANGES.md +++ b/actix-http/CHANGES.md @@ -1,13 +1,19 @@ # Changes -## [Unreleased] +## [Unreleased] - xxx + +## [2.0.0-beta.1] - 2020-07-11 ### Changed -* Migrate cookie handling to `cookie` crate. -* Update `sha-1` to 0.9 -* MSRV is now 1.41.1 -* Fix client leak [#1580] +* Migrate cookie handling to `cookie` crate. [#1558] +* Update `sha-1` to 0.9. [#1586] +* Fix leak in client pool. [#1580] +* MSRV is now 1.41.1. + +[#1558]: https://github.com/actix/actix-web/pull/1558 +[#1586]: https://github.com/actix/actix-web/pull/1586 +[#1580]: https://github.com/actix/actix-web/pull/1580 ## [2.0.0-alpha.4] - 2020-05-21 diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index 6095f89ea..a9bec59de 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "actix-http" -version = "2.0.0-alpha.4" +version = "2.0.0-beta.1" authors = ["Nikolay Kim "] -description = "Actix http primitives" +description = "Actix HTTP primitives" readme = "README.md" keywords = ["actix", "http", "framework", "async", "futures"] homepage = "https://actix.rs" From 78594a72bdd5705531e0974a65685e770f7832b9 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Tue, 14 Jul 2020 03:16:26 +0100 Subject: [PATCH 4/6] prepare awc v2.0.0-beta.1 release --- awc/CHANGES.md | 4 ++++ awc/Cargo.toml | 6 +++--- test-server/Cargo.toml | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/awc/CHANGES.md b/awc/CHANGES.md index 6d5a81b5e..19154d35d 100644 --- a/awc/CHANGES.md +++ b/awc/CHANGES.md @@ -1,5 +1,9 @@ # Changes +## [2.0.0-beta.1] - 2020-07-14 +### Changed +* Update `actix-http` dependency to 2.0.0-beta.1 + ## [2.0.0-alpha.2] - 2020-05-21 ### Changed diff --git a/awc/Cargo.toml b/awc/Cargo.toml index b36e735ca..e0f89c8dc 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "awc" -version = "2.0.0-alpha.2" +version = "2.0.0-beta.1" authors = ["Nikolay Kim "] description = "Actix http client." readme = "README.md" @@ -36,7 +36,7 @@ compress = ["actix-http/compress"] [dependencies] actix-codec = "0.2.0" actix-service = "1.0.1" -actix-http = "2.0.0-alpha.4" +actix-http = "2.0.0-beta.1" actix-rt = "1.0.0" base64 = "0.12" @@ -56,7 +56,7 @@ rust-tls = { version = "0.17.0", package = "rustls", optional = true, features = [dev-dependencies] actix-connect = { version = "2.0.0-alpha.2", features = ["openssl"] } actix-web = { version = "3.0.0-alpha.3", features = ["openssl"] } -actix-http = { version = "2.0.0-alpha.4", features = ["openssl"] } +actix-http = { version = "2.0.0-beta.1", features = ["openssl"] } actix-http-test = { version = "2.0.0-alpha.1", features = ["openssl"] } actix-utils = "1.0.3" actix-server = "1.0.0" diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml index 2c526e672..aeb40daee 100644 --- a/test-server/Cargo.toml +++ b/test-server/Cargo.toml @@ -2,7 +2,7 @@ name = "actix-http-test" version = "2.0.0-alpha.1" authors = ["Nikolay Kim "] -description = "Actix http test server" +description = "Actix HTTP test server" readme = "README.md" keywords = ["http", "web", "framework", "async", "futures"] homepage = "https://actix.rs" @@ -53,4 +53,4 @@ open-ssl = { version = "0.10", package = "openssl", optional = true } [dev-dependencies] actix-web = "3.0.0-alpha.3" -actix-http = "2.0.0-alpha.4" +actix-http = "2.0.0-beta.1" From 1382094c152d9d201513ae280934d58fc5158b40 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Tue, 14 Jul 2020 11:19:56 +0900 Subject: [PATCH 5/6] Avoid using deprecated `/` in license field --- Cargo.toml | 2 +- actix-files/Cargo.toml | 2 +- actix-http/Cargo.toml | 2 +- actix-multipart/Cargo.toml | 2 +- actix-web-actors/Cargo.toml | 2 +- actix-web-codegen/Cargo.toml | 2 +- awc/Cargo.toml | 2 +- test-server/Cargo.toml | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8c4719b92..146c4004f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/actix-web/" categories = ["network-programming", "asynchronous", "web-programming::http-server", "web-programming::websocket"] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [package.metadata.docs.rs] diff --git a/actix-files/Cargo.toml b/actix-files/Cargo.toml index 12fd03ce1..b7ba75960 100644 --- a/actix-files/Cargo.toml +++ b/actix-files/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://actix.rs" repository = "https://github.com/actix/actix-web.git" documentation = "https://docs.rs/actix-files/" categories = ["asynchronous", "web-programming::http-server"] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [lib] diff --git a/actix-http/Cargo.toml b/actix-http/Cargo.toml index a9bec59de..232b5c3f0 100644 --- a/actix-http/Cargo.toml +++ b/actix-http/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/actix-http/" categories = ["network-programming", "asynchronous", "web-programming::http-server", "web-programming::websocket"] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [package.metadata.docs.rs] diff --git a/actix-multipart/Cargo.toml b/actix-multipart/Cargo.toml index c5f315d75..f6d6a37a1 100644 --- a/actix-multipart/Cargo.toml +++ b/actix-multipart/Cargo.toml @@ -8,7 +8,7 @@ keywords = ["http", "web", "framework", "async", "futures"] homepage = "https://actix.rs" repository = "https://github.com/actix/actix-web.git" documentation = "https://docs.rs/actix-multipart/" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [lib] diff --git a/actix-web-actors/Cargo.toml b/actix-web-actors/Cargo.toml index 746aca2d5..7383b2032 100644 --- a/actix-web-actors/Cargo.toml +++ b/actix-web-actors/Cargo.toml @@ -8,7 +8,7 @@ keywords = ["actix", "http", "web", "framework", "async"] homepage = "https://actix.rs" repository = "https://github.com/actix/actix-web.git" documentation = "https://docs.rs/actix-web-actors/" -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [lib] diff --git a/actix-web-codegen/Cargo.toml b/actix-web-codegen/Cargo.toml index 178eeeb7e..10c33ea74 100644 --- a/actix-web-codegen/Cargo.toml +++ b/actix-web-codegen/Cargo.toml @@ -7,7 +7,7 @@ homepage = "https://actix.rs" repository = "https://github.com/actix/actix-web" documentation = "https://docs.rs/actix-web-codegen" authors = ["Nikolay Kim "] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [lib] diff --git a/awc/Cargo.toml b/awc/Cargo.toml index b36e735ca..563c5cae5 100644 --- a/awc/Cargo.toml +++ b/awc/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/awc/" categories = ["network-programming", "asynchronous", "web-programming::http-client", "web-programming::websocket"] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" edition = "2018" [lib] diff --git a/test-server/Cargo.toml b/test-server/Cargo.toml index 2c526e672..1cdf77031 100644 --- a/test-server/Cargo.toml +++ b/test-server/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/actix-http-test/" categories = ["network-programming", "asynchronous", "web-programming::http-server", "web-programming::websocket"] -license = "MIT/Apache-2.0" +license = "MIT OR Apache-2.0" exclude = [".gitignore", ".cargo/config"] edition = "2018" From ad7c6d26332395e4693a68da8c15de799b259ca5 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 15 Jul 2020 00:44:44 +0100 Subject: [PATCH 6/6] prepare actix-web v3.0.0-beta.1 release (#1600) --- CHANGES.md | 14 ++++---------- Cargo.toml | 6 +++--- actix-web-codegen/CHANGES.md | 11 ++++++----- actix-web-codegen/Cargo.toml | 4 ++-- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 8f15eea15..149ff8fcb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,38 +1,32 @@ # Changes -## [Unreleased] +## Unreleased - 2020-xx-xx + +## 3.0.0-beta.1 - 2020-07-13 ### Added - * Re-export `actix_rt::main` as `actix_web::main`. * `HttpRequest::match_pattern` and `ServiceRequest::match_pattern` for extracting the matched resource pattern. * `HttpRequest::match_name` and `ServiceRequest::match_name` for extracting matched resource name. ### Changed - * Fix actix_http::h1::dispatcher so it returns when HW_BUFFER_SIZE is reached. Should reduce peak memory consumption during large uploads. [#1550] * Migrate cookie handling to `cookie` crate. Actix-web no longer requires `ring` dependency. * MSRV is now 1.41.1 ### Fixed - * `NormalizePath` improved consistency when path needs slashes added _and_ removed. -## [3.0.0-alpha.3] - 2020-05-21 +## 3.0.0-alpha.3 - 2020-05-21 ### Added - * Add option to create `Data` from `Arc` [#1509] ### Changed - * Resources and Scopes can now access non-overridden data types set on App (or containing scopes) when setting their own data. [#1486] - * Fix audit issue logging by default peer address [#1485] - * Bump minimum supported Rust version to 1.40 - * Replace deprecated `net2` crate with `socket2` [#1485]: https://github.com/actix/actix-web/pull/1485 diff --git a/Cargo.toml b/Cargo.toml index 146c4004f..49de9fd96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web" -version = "3.0.0-alpha.3" +version = "3.0.0-beta.1" authors = ["Nikolay Kim "] description = "Actix web is a simple, pragmatic and extremely fast web framework for Rust." readme = "README.md" @@ -76,9 +76,9 @@ actix-macros = "0.1.0" actix-threadpool = "0.3.1" actix-tls = "2.0.0-alpha.1" -actix-web-codegen = "0.2.2" +actix-web-codegen = "0.3.0-beta.1" actix-http = "2.0.0-alpha.4" -awc = { version = "2.0.0-alpha.2", default-features = false } +awc = { version = "2.0.0-beta.1", default-features = false } bytes = "0.5.3" derive_more = "0.99.2" diff --git a/actix-web-codegen/CHANGES.md b/actix-web-codegen/CHANGES.md index 8259aaac2..242c5f8de 100644 --- a/actix-web-codegen/CHANGES.md +++ b/actix-web-codegen/CHANGES.md @@ -1,18 +1,20 @@ # Changes -## [Unreleased] - XXXX-XX-XX +## Unreleased - 2020-xx-xx -* Add main entry-point macro that uses re-exported runtime. + +## 0.3.0-beta.1 - 2020-07-14 +* Add main entry-point macro that uses re-exported runtime. [#1559] + +[#1559]: https://github.com/actix/actix-web/pull/1559 ## [0.2.2] - 2020-05-23 - * Add resource middleware on actix-web-codegen [#1467] [#1467]: https://github.com/actix/actix-web/pull/1467 ## [0.2.1] - 2020-02-25 - * Add `#[allow(missing_docs)]` attribute to generated structs [#1368] * Allow the handler function to be named as `config` [#1290] @@ -26,7 +28,6 @@ ## [0.1.3] - 2019-10-14 * Bump up `syn` & `quote` to 1.0 - * Provide better error message ## [0.1.2] - 2019-06-04 diff --git a/actix-web-codegen/Cargo.toml b/actix-web-codegen/Cargo.toml index 10c33ea74..070c09899 100644 --- a/actix-web-codegen/Cargo.toml +++ b/actix-web-codegen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-web-codegen" -version = "0.2.2" +version = "0.3.0-beta.1" description = "Actix web proc macros" readme = "README.md" homepage = "https://actix.rs" @@ -20,5 +20,5 @@ proc-macro2 = "1" [dev-dependencies] actix-rt = "1.0.0" -actix-web = "3.0.0-alpha.3" +actix-web = "3.0.0-beta.1" futures-util = { version = "0.3.5", default-features = false }