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

Unhelpful error message when attempt to retrieve Timer handle in same line as Timer created with ::default() or ::new() #727

Closed
fordN opened this issue Oct 30, 2018 · 4 comments
Labels
E-needs-mcve Call for participation: This issue needs a Minimal Complete and Verifiable Example

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

When creating a new Timer I experience unhelpful errors if I attempt to both create the Timer and get it's handle in one line. The documentation for tokio_timer::timer::Timer::new() does suggest that the two steps must be separate by stating that "once the timer has been created, a handle can be obtained using handle"; however, it was not easy to track down with the given information especially given the Illegal Operation: 4 error I was returning when first debugging the issue.

Code

WORKS
let timer = tokio_timer::timer::Timer::new(ParkThread::new());
let timer_handle = timer.handle();
DOESNT WORK
let timer_handle = tokio_timer::timer::Timer::new(ParkThread::new()).handle();    

Errors encountered

thread panicked while processing panic. aborting.
Illegal Operation: 4

or (more helpful)

tokio timer error: timer is shutdown

More complete code example

Also found here: https://github.com/graphprotocol/graph-node/blob/ford/tokio-blockon/node/src/main.rs#L59

// Create components for tokio context: multi-threaded runtime,
// reactor reference, executor context on the runtime, and Timer handle.
let runtime = tokio::runtime::Runtime::new().expect("Failed to create runtime");
let reactor = tokio_reactor::Handle::current();
let mut enter = tokio_executor::enter()
    .expect("Failed to enter runtime executor, multiple executors at once");

// ERROR CAUSED BY FOLLOWING LINE
let timer_handle = Timer::default().handle();

// Setup runtime context with defaults
tokio_reactor::with_default(&reactor, &mut enter, |enter| {
    tokio_executor::with_default(&mut runtime.executor(), enter, |enter| {
        tokio_timer::with_default(&timer_handle, enter, |enter| {
            enter
                .block_on(future::lazy(|| async_main()))
                .expect("Failed to run main function");
        })
    })
});

runtime.shutdown_on_idle().wait().unwrap();
@fordN fordN changed the title Unhelpful error message when attempt to retrieve Timer handle at same time as Timer creation with ::default() or ::new() Unhelpful error message when attempt to retrieve Timer handle in same line as Timer created with ::default() or ::new() Oct 30, 2018
@carllerche
Copy link
Member

I can't actually actually reproduce this.

I tried running:

extern crate tokio_timer;

fn main() {
    let _timer_handle = tokio_timer::timer::Timer::default().handle();
}

@carllerche
Copy link
Member

The two lines you showed should execute identically.

@tobz
Copy link
Member

tobz commented Nov 28, 2018

@fordN Do you have a MVCE that you could provide us?

@tobz tobz added the E-needs-mcve Call for participation: This issue needs a Minimal Complete and Verifiable Example label Nov 28, 2018
@carllerche
Copy link
Member

Closing due to inactivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-mcve Call for participation: This issue needs a Minimal Complete and Verifiable Example
Projects
None yet
Development

No branches or pull requests

3 participants