From 298727dcbdf52c2fc9c8dc0b759bc99d963d1f2c Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 12 Dec 2018 19:01:59 -0800 Subject: [PATCH] back port bug fixes --- CHANGES.md | 9 +++++++++ Cargo.toml | 2 +- src/counter.rs | 14 ++++++++------ src/service/and_then.rs | 9 +++++---- src/service/then.rs | 10 ++++++---- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c282cc03..902c13c9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,14 @@ # Changes +## [0.2.5] - 2018-12-12 + +### Fixed + +* Fix back-pressure for concurrent ssl handshakes + +* Drop completed future for .then and .and_then combinators + + ## [0.2.4] - 2018-11-21 ### Added diff --git a/Cargo.toml b/Cargo.toml index 5e00dca5..c1873f27 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-net" -version = "0.2.4" +version = "0.2.5" authors = ["Nikolay Kim "] description = "Actix net - framework for the compisible network services for Rust (experimental)" readme = "README.md" diff --git a/src/counter.rs b/src/counter.rs index 1302c91c..539ce497 100644 --- a/src/counter.rs +++ b/src/counter.rs @@ -9,6 +9,7 @@ use futures::task::AtomicTask; /// Counter could be cloned, total ncount is shared across all clones. pub struct Counter(Rc); +#[derive(Debug)] struct CounterInner { count: Cell, capacity: usize, @@ -40,6 +41,7 @@ impl Counter { } } +#[derive(Debug)] pub struct CounterGuard(Rc); impl CounterGuard { @@ -57,11 +59,7 @@ impl Drop for CounterGuard { impl CounterInner { fn inc(&self) { - let num = self.count.get() + 1; - self.count.set(num); - if num == self.capacity { - self.task.register(); - } + self.count.set(self.count.get() + 1); } fn dec(&self) { @@ -73,6 +71,10 @@ impl CounterInner { } fn available(&self) -> bool { - self.count.get() < self.capacity + let avail = self.count.get() < self.capacity; + if !avail { + self.task.register(); + } + avail } } diff --git a/src/service/and_then.rs b/src/service/and_then.rs index 9dd67277..8d159ba2 100644 --- a/src/service/and_then.rs +++ b/src/service/and_then.rs @@ -63,7 +63,7 @@ where { b: Cell, fut_b: Option, - fut_a: A::Future, + fut_a: Option, } impl AndThenFuture @@ -71,10 +71,10 @@ where A: Service, B: Service, { - fn new(fut_a: A::Future, b: Cell) -> Self { + fn new(a: A::Future, b: Cell) -> Self { AndThenFuture { b, - fut_a, + fut_a: Some(a), fut_b: None, } } @@ -94,8 +94,9 @@ where return fut.poll(); } - match self.fut_a.poll() { + match self.fut_a.as_mut().expect("actix-net bug").poll() { Ok(Async::Ready(resp)) => { + let _ = self.fut_a.take(); self.fut_b = Some(self.b.borrow_mut().call(resp)); self.poll() } diff --git a/src/service/then.rs b/src/service/then.rs index b10537b5..8b8890b5 100644 --- a/src/service/then.rs +++ b/src/service/then.rs @@ -63,7 +63,7 @@ where { b: Cell, fut_b: Option, - fut_a: A::Future, + fut_a: Option, } impl ThenFuture @@ -71,10 +71,10 @@ where A: Service, B: Service>, { - fn new(fut_a: A::Future, b: Cell) -> Self { + fn new(a: A::Future, b: Cell) -> Self { ThenFuture { b, - fut_a, + fut_a: Some(a), fut_b: None, } } @@ -93,12 +93,14 @@ where return fut.poll(); } - match self.fut_a.poll() { + match self.fut_a.as_mut().expect("actix-net bug").poll() { Ok(Async::Ready(resp)) => { + let _ = self.fut_a.take(); self.fut_b = Some(self.b.borrow_mut().call(Ok(resp))); self.poll() } Err(err) => { + let _ = self.fut_a.take(); self.fut_b = Some(self.b.borrow_mut().call(Err(err))); self.poll() }