diff --git a/Cargo.lock b/Cargo.lock index 60a504d..2f2a316 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -888,7 +888,7 @@ dependencies = [ "mimalloc", "pin-project", "proxy-protocol", - "realm_io 0.2.5", + "realm_io 0.2.6", "serde", "serde_json", "socket2 0.4.4", @@ -905,7 +905,7 @@ dependencies = [ "lazy_static", "log", "pin-project", - "realm_io 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "realm_io 0.2.5", "realm_syscall 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio", "trust-dns-resolver 0.21.2", @@ -914,6 +914,8 @@ dependencies = [ [[package]] name = "realm_io" version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "214919adf97309686e1f07abb4cf5245fd6a165e0b9ee9a50c98c949cf44eab2" dependencies = [ "libc", "tokio", @@ -921,9 +923,7 @@ dependencies = [ [[package]] name = "realm_io" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "214919adf97309686e1f07abb4cf5245fd6a165e0b9ee9a50c98c949cf44eab2" +version = "0.2.6" dependencies = [ "libc", "tokio", diff --git a/Cargo.toml b/Cargo.toml index d87cbb4..02ccfb9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -86,6 +86,7 @@ transport = ["kaminari"] transport-boost = [] proxy-protocol = ["haproxy"] multi-thread = ["tokio/rt-multi-thread"] +brutal-shutdown = ["realm_io/brutal-shutdown"] jemalloc = ["jemallocator"] mi-malloc = ["mimalloc"] diff --git a/realm_io/Cargo.toml b/realm_io/Cargo.toml index bf24696..a0b5d61 100644 --- a/realm_io/Cargo.toml +++ b/realm_io/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "realm_io" -version = "0.2.5" +version = "0.2.6" authors = ["zephyr "] description = "Realm's high performance IO collections." repository = "https://github.com/zhboner/realm/realm_io" @@ -16,3 +16,7 @@ tokio = "1.9" [target.'cfg(unix)'.dependencies] tokio = { version = "1.9", features = ["net"] } + +[features] +default = [] +brutal-shutdown = [] diff --git a/realm_io/src/bidi_copy.rs b/realm_io/src/bidi_copy.rs index 9a325f4..b75042f 100644 --- a/realm_io/src/bidi_copy.rs +++ b/realm_io/src/bidi_copy.rs @@ -118,12 +118,23 @@ where let a_to_b = transfer(cx, a_to_b, a, b, ab_amt)?; let b_to_a = transfer2::(cx, b_to_a, b, a, ba_amt)?; - // It is not a problem if ready! returns early because transfer_one_direction for the - // other direction will keep returning TransferState::Done(count) in future calls to poll - ready!(a_to_b); - ready!(b_to_a); + // graceful shutdown + #[cfg(not(feature = "brutal-shutdown"))] + { + ready!(a_to_b); + ready!(b_to_a); + Poll::Ready(Ok(())) + } - Poll::Ready(Ok(())) + // brutal shutdown + #[cfg(feature = "brutal-shutdown")] + { + if a_to_b.is_ready() || b_to_a.is_ready() { + Poll::Ready(Ok(())) + }else { + Poll::Pending + } + } } }