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

Can't run my own Tokio reactor in netsim #27

Open
povilasb opened this issue May 11, 2019 · 0 comments
Open

Can't run my own Tokio reactor in netsim #27

povilasb opened this issue May 11, 2019 · 0 comments

Comments

@povilasb
Copy link
Collaborator

So with the latest tokio integrated (#25) now it won't allow to spawn another tokio reactor when netsim is running. So smth like this is not possible:

use futures::future;
use netsim::{Network, node, Ipv4Range};
use tokio::runtime::current_thread::Runtime;
use unwrap::unwrap;

fn main() {
    let network = Network::new();
    let network_handle = network.handle();

    let node1 = node::ipv4::machine(move |ip| {
        println!("node1: {}", ip);

        let fut = future::ok::<_, ()>(());
        let mut evloop = unwrap!(Runtime::new());
        unwrap!(evloop.block_on(fut));

        future::ok(())
    });

    let fut = future::lazy(move || {
        let (spawn_complete, _ip_plug) = network_handle.spawn_ipv4_tree(Ipv4Range::global(), node1);
        spawn_complete
    });
    let mut evloop = unwrap!(Runtime::new());
    unwrap!(evloop.block_on(fut));
}

and results with an error:

thread '<unnamed>' panicked at 'Multiple executors at once: EnterError { reason: "attempted to run an executor while another executor is already running" }', src/libcore/result.rs:997:5

In most cases when we have futures code this should not be a problem. Although, I can see 2 cases where it will be:

  1. when we have a piece of code that internally runs tokio reactor;
  2. when we have futures that do not implement Send trait.

The first thing we could do here is at least document the situation.
Another thing to consider is to provide a netsim machine node that runs on a forked process instead of a thread.

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

1 participant