tk-listen
tk-listen copied to clipboard
Delay never fails
Hi, I'm on a mac and I keep getting the following error. Seems like it does in fact sometimes fails.
thread 'main' panicked at 'delay never fails: Error(Shutdown)', libcore/result.rs:945:5
stack backtrace:
0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
1: std::sys_common::backtrace::print
2: std::panicking::default_hook::{{closure}}
3: std::panicking::default_hook
4: std::panicking::rust_panic_with_hook
5: std::panicking::begin_panic_fmt
6: rust_begin_unwind
7: core::panicking::panic_fmt
8: core::result::unwrap_failed
9: <tk_listen::sleep_on_error::SleepOnError<S> as futures::stream::Stream>::poll
10: <futures::stream::map::Map<S, F> as futures::stream::Stream>::poll
11: futures::task_impl::std::set
12: <std::thread::local::LocalKey<T>>::with
13: tokio_current_thread::block_on_all
14: proxy::main
15: std::rt::lang_start::{{closure}}
16: std::panicking::try::do_call
17: __rust_maybe_catch_panic
18: std::rt::lang_start_internal
19: main
Wow! That's interesting. It seems changed since tokio-core times :( I'm not entirely sure that this is a bug though.
I.e. it will probably work if you have an explicit way to shutdown the listener:
let (tx, rx) = oneshot::channel()
spawn(listener.select(rx)); // some type conversions needed
Can you show more code of how do you use block_on_all?
Frankly, I'm not sure how to handle error. The issue is that if we return Err from a stream then listener.buffer_unordered(n) might close prematurely. Returning "end of stream" seems invalid too.
It's also unclear what to do with "at_capacity" errors. Skipping a timer in that case defeats the whole purpose of "preventing DoS" that this timer is for.