Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tokio-stream chunks_timeout only works in a tokio runtime context #5031

Closed
xmakro opened this issue Sep 19, 2022 · 1 comment · Fixed by #5036
Closed

tokio-stream chunks_timeout only works in a tokio runtime context #5031

xmakro opened this issue Sep 19, 2022 · 1 comment · Fixed by #5036
Labels
A-tokio-stream Area: The tokio-stream crate C-bug Category: This is a bug. E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue. M-time Module: tokio/time

Comments

@xmakro
Copy link
Contributor

xmakro commented Sep 19, 2022

Version
tokio-stream 0.1.10

Description

ChunkTimeout::new calls tokio::time::sleep (see code) which can only be called in a tokio runtime context. This is undesirable as constructing the stream is often done outside a runtime. It should be possible to change deadline to Option and initialize it with None instead. The call to sleep is only used to generate a default value, but the actual deadline is not used in poll, instead it is overwritten (see code).

I tried this code:

use std::time::Duration;
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use tokio_stream::StreamExt;

fn main() {
  let (sender, receiver) = mpsc::channel(8);
  let receiver = ReceiverStream::new(receiver).chunks_timeout(4, Duration::from_millis(10));
  drop(sender);
  drop(receiver);
}

I expected to see this happen:

Run without crashing.

Instead, this happened:

thread '<unnamed>' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', third_party/rust/tokio/v1/src/runtime/context.rs:54:13
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_display
   3: core::panicking::panic_str
   4: core::option::expect_failed
   5: tokio::runtime::context::time_handle
   6: tokio::time::driver::sleep::sleep
   7: tokio_stream::stream_ext::StreamExt::chunks_timeout
@xmakro xmakro added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Sep 19, 2022
@Darksonn Darksonn added M-time Module: tokio/time A-tokio-stream Area: The tokio-stream crate E-help-wanted Call for participation: Help is requested to fix this issue. E-easy Call for participation: Experience needed to fix: Easy / not much and removed A-tokio Area: The main tokio crate labels Sep 19, 2022
@Darksonn
Copy link
Contributor

Ah, yes, it would be nice to fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-stream Area: The tokio-stream crate C-bug Category: This is a bug. E-easy Call for participation: Experience needed to fix: Easy / not much E-help-wanted Call for participation: Help is requested to fix this issue. M-time Module: tokio/time
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants