mirror of
https://github.com/ntex-rs/ntex.git
synced 2025-04-04 13:27:39 +03:00
Fix error handing for nested filters
This commit is contained in:
parent
8b3a1bc474
commit
89f758f8c4
15 changed files with 71 additions and 75 deletions
|
@ -1,5 +1,9 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.1.0-b.8] - 2021-12-28
|
||||||
|
|
||||||
|
* Fix error handing for nested filters
|
||||||
|
|
||||||
## [0.1.0-b.7] - 2021-12-27
|
## [0.1.0-b.7] - 2021-12-27
|
||||||
|
|
||||||
* Do not swallow decoded read bytes in case of filter error
|
* Do not swallow decoded read bytes in case of filter error
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ntex-io"
|
name = "ntex-io"
|
||||||
version = "0.1.0-b.7"
|
version = "0.1.0-b.8"
|
||||||
authors = ["ntex contributors <team@ntex.rs>"]
|
authors = ["ntex contributors <team@ntex.rs>"]
|
||||||
description = "Utilities for encoding and decoding frames"
|
description = "Utilities for encoding and decoding frames"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
|
@ -27,7 +27,7 @@ tokio = ["tok-io/net", "tok-io/rt"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ntex-codec = "0.6.0"
|
ntex-codec = "0.6.0"
|
||||||
ntex-bytes = "0.1.8"
|
ntex-bytes = "0.1.8"
|
||||||
ntex-util = "0.1.4"
|
ntex-util = "0.1.5"
|
||||||
ntex-service = "0.3.0-b.0"
|
ntex-service = "0.3.0-b.0"
|
||||||
|
|
||||||
bitflags = "1.3"
|
bitflags = "1.3"
|
||||||
|
|
|
@ -45,19 +45,13 @@ impl Filter for Base {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn want_shutdown(&self) {
|
fn want_shutdown(&self, err: Option<io::Error>) {
|
||||||
let mut flags = self.0.flags();
|
self.0 .0.init_shutdown(err);
|
||||||
if !flags.intersects(Flags::IO_ERR | Flags::IO_SHUTDOWN) {
|
|
||||||
flags.insert(Flags::IO_SHUTDOWN);
|
|
||||||
self.0.set_flags(flags);
|
|
||||||
self.0 .0.read_task.wake();
|
|
||||||
self.0 .0.write_task.wake();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn poll_shutdown(&self) -> Poll<io::Result<()>> {
|
fn poll_shutdown(&self) -> Poll<io::Result<()>> {
|
||||||
self.want_shutdown();
|
self.want_shutdown(None);
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,7 +150,7 @@ impl Filter for NullFilter {
|
||||||
|
|
||||||
fn want_read(&self) {}
|
fn want_read(&self) {}
|
||||||
|
|
||||||
fn want_shutdown(&self) {}
|
fn want_shutdown(&self, _: Option<io::Error>) {}
|
||||||
|
|
||||||
fn poll_shutdown(&self) -> Poll<io::Result<()>> {
|
fn poll_shutdown(&self) -> Poll<io::Result<()>> {
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
|
|
|
@ -126,46 +126,37 @@ impl IoState {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
/// Gracefully shutdown read and write io tasks
|
/// Gracefully shutdown read and write io tasks
|
||||||
pub(super) fn init_shutdown(&self, cx: Option<&mut Context<'_>>) {
|
pub(super) fn init_shutdown(&self, err: Option<io::Error>) {
|
||||||
let flags = self.flags.get();
|
let flags = self.flags.get();
|
||||||
|
|
||||||
if !flags.intersects(Flags::IO_ERR | Flags::IO_SHUTDOWN | Flags::IO_FILTERS) {
|
if !flags.intersects(Flags::IO_ERR | Flags::IO_SHUTDOWN | Flags::IO_FILTERS) {
|
||||||
log::trace!("initiate io shutdown {:?}", flags);
|
log::trace!("initiate io shutdown {:?} {:?}", flags, err);
|
||||||
self.insert_flags(Flags::IO_FILTERS);
|
self.insert_flags(Flags::IO_FILTERS);
|
||||||
if let Err(err) = self.shutdown_filters() {
|
|
||||||
self.error.set(Some(err));
|
|
||||||
}
|
|
||||||
|
|
||||||
self.read_task.wake();
|
self.read_task.wake();
|
||||||
self.write_task.wake();
|
self.write_task.wake();
|
||||||
if let Some(cx) = cx {
|
if let Some(err) = err {
|
||||||
self.dispatch_task.register(cx.waker());
|
self.error.set(Some(err));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub(super) fn shutdown_filters(&self) -> io::Result<()> {
|
pub(super) fn shutdown_filters(&self) {
|
||||||
let mut flags = self.flags.get();
|
let mut flags = self.flags.get();
|
||||||
if !flags.intersects(Flags::IO_ERR | Flags::IO_SHUTDOWN) {
|
if !flags.intersects(Flags::IO_ERR | Flags::IO_SHUTDOWN) {
|
||||||
let result = match self.filter.get().poll_shutdown() {
|
match self.filter.get().poll_shutdown() {
|
||||||
Poll::Pending => return Ok(()),
|
Poll::Pending => return,
|
||||||
Poll::Ready(Ok(())) => {
|
Poll::Ready(Ok(())) => {
|
||||||
flags.insert(Flags::IO_SHUTDOWN);
|
flags.insert(Flags::IO_SHUTDOWN);
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
Poll::Ready(Err(err)) => {
|
Poll::Ready(Err(err)) => {
|
||||||
flags.insert(Flags::IO_ERR);
|
flags.insert(Flags::IO_ERR);
|
||||||
self.dispatch_task.wake();
|
self.error.set(Some(err));
|
||||||
Err(err)
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
self.flags.set(flags);
|
self.flags.set(flags);
|
||||||
self.read_task.wake();
|
self.read_task.wake();
|
||||||
self.write_task.wake();
|
self.write_task.wake();
|
||||||
result
|
self.dispatch_task.wake();
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -630,7 +621,7 @@ impl<F> Io<F> {
|
||||||
Poll::Ready(Ok(()))
|
Poll::Ready(Ok(()))
|
||||||
} else {
|
} else {
|
||||||
if !flags.contains(Flags::IO_FILTERS) {
|
if !flags.contains(Flags::IO_FILTERS) {
|
||||||
self.0 .0.init_shutdown(Some(cx));
|
self.0 .0.init_shutdown(None);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(err) = self.0 .0.error.take() {
|
if let Some(err) = self.0 .0.error.take() {
|
||||||
|
|
|
@ -55,7 +55,7 @@ pub trait Filter: 'static {
|
||||||
fn want_read(&self);
|
fn want_read(&self);
|
||||||
|
|
||||||
/// Filter wants gracefully shutdown io stream
|
/// Filter wants gracefully shutdown io stream
|
||||||
fn want_shutdown(&self);
|
fn want_shutdown(&self, err: Option<sio::Error>);
|
||||||
|
|
||||||
fn poll_shutdown(&self) -> Poll<sio::Result<()>>;
|
fn poll_shutdown(&self) -> Poll<sio::Result<()>>;
|
||||||
|
|
||||||
|
|
|
@ -31,19 +31,16 @@ impl ReadContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn release_read_buf(&self, buf: BytesMut, nbytes: usize) -> Result<(), io::Error> {
|
pub fn release_read_buf(&self, buf: BytesMut, nbytes: usize) {
|
||||||
if buf.is_empty() {
|
if buf.is_empty() {
|
||||||
self.0.memory_pool().release_read_buf(buf);
|
self.0.memory_pool().release_read_buf(buf);
|
||||||
Ok(())
|
|
||||||
} else {
|
} else {
|
||||||
|
let filter = self.0.filter();
|
||||||
let mut dst = self.0 .0.read_buf.take();
|
let mut dst = self.0 .0.read_buf.take();
|
||||||
let result = self.0.filter().release_read_buf(buf, &mut dst, nbytes);
|
let result = filter.release_read_buf(buf, &mut dst, nbytes);
|
||||||
let nbytes = result.as_ref().map(|i| *i).unwrap_or(0);
|
let nbytes = result.as_ref().map(|i| *i).unwrap_or(0);
|
||||||
|
|
||||||
if let Some(dst) = dst {
|
if let Some(dst) = dst {
|
||||||
if self.0.flags().contains(Flags::IO_FILTERS) {
|
|
||||||
self.0 .0.shutdown_filters()?;
|
|
||||||
}
|
|
||||||
if nbytes > 0 {
|
if nbytes > 0 {
|
||||||
if dst.len() > self.0.memory_pool().read_params().high as usize {
|
if dst.len() > self.0.memory_pool().read_params().high as usize {
|
||||||
log::trace!(
|
log::trace!(
|
||||||
|
@ -66,11 +63,13 @@ impl ReadContext {
|
||||||
if let Err(err) = result {
|
if let Err(err) = result {
|
||||||
self.0 .0.dispatch_task.wake();
|
self.0 .0.dispatch_task.wake();
|
||||||
self.0 .0.insert_flags(Flags::RD_READY);
|
self.0 .0.insert_flags(Flags::RD_READY);
|
||||||
Err(err)
|
filter.want_shutdown(Some(err));
|
||||||
} else {
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.0.flags().contains(Flags::IO_FILTERS) {
|
||||||
|
self.0 .0.shutdown_filters();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +121,7 @@ impl WriteContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
if flags.contains(Flags::IO_FILTERS) {
|
if flags.contains(Flags::IO_FILTERS) {
|
||||||
self.0 .0.shutdown_filters()?;
|
self.0 .0.shutdown_filters();
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,10 +100,8 @@ impl Future for ReadTask {
|
||||||
this.state.close(None);
|
this.state.close(None);
|
||||||
return Poll::Ready(());
|
return Poll::Ready(());
|
||||||
}
|
}
|
||||||
return if let Err(e) = this.state.release_read_buf(buf, new_bytes) {
|
this.state.release_read_buf(buf, new_bytes);
|
||||||
this.state.close(Some(e));
|
return if close {
|
||||||
Poll::Ready(())
|
|
||||||
} else if close {
|
|
||||||
this.state.close(None);
|
this.state.close(None);
|
||||||
Poll::Ready(())
|
Poll::Ready(())
|
||||||
} else if pending {
|
} else if pending {
|
||||||
|
@ -525,10 +523,8 @@ mod unixstream {
|
||||||
this.state.close(None);
|
this.state.close(None);
|
||||||
return Poll::Ready(());
|
return Poll::Ready(());
|
||||||
}
|
}
|
||||||
return if let Err(e) = this.state.release_read_buf(buf, new_bytes) {
|
this.state.release_read_buf(buf, new_bytes);
|
||||||
this.state.close(Some(e));
|
return if close {
|
||||||
Poll::Ready(())
|
|
||||||
} else if close {
|
|
||||||
this.state.close(None);
|
this.state.close(None);
|
||||||
Poll::Ready(())
|
Poll::Ready(())
|
||||||
} else if pending {
|
} else if pending {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ntex-tls"
|
name = "ntex-tls"
|
||||||
version = "0.1.0-b.4"
|
version = "0.1.0-b.5"
|
||||||
authors = ["ntex contributors <team@ntex.rs>"]
|
authors = ["ntex contributors <team@ntex.rs>"]
|
||||||
description = "An implementation of SSL streams for ntex backed by OpenSSL"
|
description = "An implementation of SSL streams for ntex backed by OpenSSL"
|
||||||
keywords = ["network", "framework", "async", "futures"]
|
keywords = ["network", "framework", "async", "futures"]
|
||||||
|
@ -26,8 +26,8 @@ rustls = ["tls_rust"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ntex-bytes = "0.1.8"
|
ntex-bytes = "0.1.8"
|
||||||
ntex-io = "0.1.0-b.6"
|
ntex-io = "0.1.0-b.8"
|
||||||
ntex-util = "0.1.4"
|
ntex-util = "0.1.5"
|
||||||
ntex-service = "0.3.0-b.0"
|
ntex-service = "0.3.0-b.0"
|
||||||
pin-project-lite = "0.2"
|
pin-project-lite = "0.2"
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,8 @@ impl<F: Filter> Filter for SslFilter<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn want_shutdown(&self) {
|
fn want_shutdown(&self, err: Option<io::Error>) {
|
||||||
self.inner.borrow().get_ref().inner.want_shutdown()
|
self.inner.borrow().get_ref().inner.want_shutdown(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -157,10 +157,13 @@ impl<F: Filter> Filter for SslFilter<F> {
|
||||||
let pool = {
|
let pool = {
|
||||||
let mut inner = self.inner.borrow_mut();
|
let mut inner = self.inner.borrow_mut();
|
||||||
let mut dst = None;
|
let mut dst = None;
|
||||||
inner
|
let result = inner
|
||||||
.get_ref()
|
.get_ref()
|
||||||
.inner
|
.inner
|
||||||
.release_read_buf(src, &mut dst, nbytes)?;
|
.release_read_buf(src, &mut dst, nbytes);
|
||||||
|
if let Err(err) = result {
|
||||||
|
self.want_shutdown(Some(err));
|
||||||
|
}
|
||||||
if dst.is_some() {
|
if dst.is_some() {
|
||||||
inner.get_mut().read_buf = dst;
|
inner.get_mut().read_buf = dst;
|
||||||
inner.get_ref().pool
|
inner.get_ref().pool
|
||||||
|
|
|
@ -52,8 +52,8 @@ impl<F: Filter> Filter for TlsClientFilter<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn want_shutdown(&self) {
|
fn want_shutdown(&self, err: Option<io::Error>) {
|
||||||
self.inner.borrow().inner.want_shutdown()
|
self.inner.borrow().inner.want_shutdown(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -111,7 +111,9 @@ impl<F: Filter> Filter for TlsClientFilter<F> {
|
||||||
} else {
|
} else {
|
||||||
let mut src = {
|
let mut src = {
|
||||||
let mut dst = None;
|
let mut dst = None;
|
||||||
inner.inner.release_read_buf(src, &mut dst, nbytes)?;
|
if let Err(err) = inner.inner.release_read_buf(src, &mut dst, nbytes) {
|
||||||
|
self.want_shutdown(Some(err));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(dst) = dst {
|
if let Some(dst) = dst {
|
||||||
dst
|
dst
|
||||||
|
|
|
@ -77,10 +77,10 @@ impl<F: Filter> Filter for TlsFilter<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn want_shutdown(&self) {
|
fn want_shutdown(&self, err: Option<io::Error>) {
|
||||||
match self.inner {
|
match self.inner {
|
||||||
InnerTlsFilter::Server(ref f) => f.want_shutdown(),
|
InnerTlsFilter::Server(ref f) => f.want_shutdown(err),
|
||||||
InnerTlsFilter::Client(ref f) => f.want_shutdown(),
|
InnerTlsFilter::Client(ref f) => f.want_shutdown(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,8 @@ impl<F: Filter> Filter for TlsServerFilter<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn want_shutdown(&self) {
|
fn want_shutdown(&self, err: Option<io::Error>) {
|
||||||
self.inner.borrow().inner.want_shutdown()
|
self.inner.borrow().inner.want_shutdown(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -111,7 +111,9 @@ impl<F: Filter> Filter for TlsServerFilter<F> {
|
||||||
} else {
|
} else {
|
||||||
let mut src = {
|
let mut src = {
|
||||||
let mut dst = None;
|
let mut dst = None;
|
||||||
inner.inner.release_read_buf(src, &mut dst, nbytes)?;
|
if let Err(e) = inner.inner.release_read_buf(src, &mut dst, nbytes) {
|
||||||
|
self.want_shutdown(Some(e));
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(dst) = dst {
|
if let Some(dst) = dst {
|
||||||
dst
|
dst
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
# Changes
|
# Changes
|
||||||
|
|
||||||
|
## [0.5.0-b.5] - 2021-12-xx
|
||||||
|
|
||||||
|
* Fix handling for ws transport nested errors
|
||||||
|
|
||||||
## [0.5.0-b.4] - 2021-12-26
|
## [0.5.0-b.4] - 2021-12-26
|
||||||
|
|
||||||
* Allow to get access to ws transport codec
|
* Allow to get access to ws transport codec
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "ntex"
|
name = "ntex"
|
||||||
version = "0.5.0-b.4"
|
version = "0.5.0-b.5"
|
||||||
authors = ["ntex contributors <team@ntex.rs>"]
|
authors = ["ntex contributors <team@ntex.rs>"]
|
||||||
description = "Framework for composable network services"
|
description = "Framework for composable network services"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -43,10 +43,10 @@ ntex-codec = "0.6.0"
|
||||||
ntex-router = "0.5.1"
|
ntex-router = "0.5.1"
|
||||||
ntex-service = "0.3.0-b.0"
|
ntex-service = "0.3.0-b.0"
|
||||||
ntex-macros = "0.1.3"
|
ntex-macros = "0.1.3"
|
||||||
ntex-util = "0.1.4"
|
ntex-util = "0.1.5"
|
||||||
ntex-bytes = "0.1.8"
|
ntex-bytes = "0.1.8"
|
||||||
ntex-tls = "0.1.0-b.4"
|
ntex-tls = "0.1.0-b.5"
|
||||||
ntex-io = "0.1.0-b.6"
|
ntex-io = "0.1.0-b.8"
|
||||||
ntex-rt = { version = "0.4.0-b.2", default-features = false, features = ["tokio"] }
|
ntex-rt = { version = "0.4.0-b.2", default-features = false, features = ["tokio"] }
|
||||||
|
|
||||||
base64 = "0.13"
|
base64 = "0.13"
|
||||||
|
|
|
@ -65,8 +65,8 @@ impl<F: Filter> Filter for WsTransport<F> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn want_shutdown(&self) {
|
fn want_shutdown(&self, err: Option<io::Error>) {
|
||||||
self.inner.want_shutdown()
|
self.inner.want_shutdown(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -107,8 +107,9 @@ impl<F: Filter> Filter for WsTransport<F> {
|
||||||
) -> io::Result<usize> {
|
) -> io::Result<usize> {
|
||||||
let mut src = {
|
let mut src = {
|
||||||
let mut dst = None;
|
let mut dst = None;
|
||||||
self.inner.release_read_buf(src, &mut dst, nbytes)?;
|
if let Err(err) = self.inner.release_read_buf(src, &mut dst, nbytes) {
|
||||||
|
self.want_shutdown(Some(err));
|
||||||
|
}
|
||||||
if let Some(dst) = dst {
|
if let Some(dst) = dst {
|
||||||
dst
|
dst
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue