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

Errors because runtime::Runtime::block_on() does not set reactor, executor, or timer defaults for the context #728

Closed
fordN opened this issue Oct 30, 2018 · 2 comments

Comments

@fordN
Copy link

fordN commented Oct 30, 2018

Version

tokio-io v0.1.7
tokio-codec v0.1.0
tokio-current-thread v0.1.3
tokio-dns-unofficial v0.3.1
tokio-executor v0.1.5 
tokio-fs v0.1.3
tokio-proto v0.1.1
tokio-io v0.1.7
tokio-threadpool v0.1.5
tokio-reactor v0.1.6
tokio-udp v0.1.1
tokio-uds v0.2.2
tokio-tcp v0.1.0
tokio-timer v0.2.7
tokio-tls v0.2.0
tokio-tungstenite v0.6.0

Platform

Darwin Kernel Version 16.7.0: Thu Jun 21 20:07:39 PDT 2018; root:xnu-3789.73.14~1/RELEASE_X86_64 x86_64

Subcrates

tokio-reactor = "0.1.6"
tokio-retry = "0.2"
tokio-timer = "0.2.7"

Description

Tokio::runtime::Runtime::block_on does not work as expected. For my use case it would be great if it could be used similarly to tokio::run. I am replacing tokio::run in order to allow the entire runtime to shutdown gracefully if a panic occurs in a spawned future.

I tried this

runtime.block_on(future::lazy(|| main()))

which returned: error on unwrap: 'Value: Canceled' suggesting that the oneshot sender created in block_on was getting dropped early. I also saw SpawnError {shutdown: is_true} during development.
I eventually was successful by using tokio_executor::with_default() to set the executor as the default for the runtime context. I then experienced similar errors for timer when I tried to implement a timeout(); this required the same solution, tokio_timer::with_default(). In the end I am not using runtime::block_on directly instead using tokio_executor::Enter::block_on() within the context of default reactor, executor, and timer that I set up.
It would be great to have something similar to block_on that sets these defaults, or a way to easily create the defaults through the runtime rather then bringing in tokio_executor, tokio_reactor, and tokio_timer for access to their with_default methods...or some clear documentation in block_on hinting at the lack of defaults and where that could cause problems within the runtime context.

Sample runtime context setup with defaults for ::block_on

https://github.com/graphprotocol/graph-node/blob/ford/tokio-blockon/node/src/main.rs#L67

@fordN fordN changed the title Difficulty using runtime::Runtime::block_on() Errors because runtime::Runtime::block_on() does not set reactor, executor, or timer defaults Oct 30, 2018
@fordN fordN changed the title Errors because runtime::Runtime::block_on() does not set reactor, executor, or timer defaults Errors because runtime::Runtime::block_on() does not set reactor, executor, or timer defaults for the context Oct 30, 2018
@carllerche
Copy link
Member

I'm looking at block_on and it looks like it should have access to everything. Could you provide a minimal repro that I can run to see the problem?

The future gets spawned onto the runtime, which should have everything configured (code).

@carllerche
Copy link
Member

Closing cue to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants