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

Example code does not work out of the box #7

Open
ydirson opened this issue Feb 20, 2023 · 1 comment
Open

Example code does not work out of the box #7

ydirson opened this issue Feb 20, 2023 · 1 comment

Comments

@ydirson
Copy link

ydirson commented Feb 20, 2023

Code samples "dumping all the machine’s links does not work out of the box:

  • tokio dependency has to activate features (not sure what the minimal is, feature full does work)
  • several names imported from netlink-proto-route are indeed implemented in netlink-proto-core

Did this example ever compile ? If it did, I feel it hints toward incompatible changes in the API that should have caused version bumps.

@ydirson ydirson changed the title Example code does not work Example code does not work out of the box Feb 21, 2023
@ydirson
Copy link
Author

ydirson commented Feb 21, 2023

Another one is https://github.com/rust-netlink/netlink-proto/blob/main/examples/dump_links_async.rs.

  • figured out similarly that the use section should rather be like:
    use netlink_packet_core::{
        NetlinkHeader, NetlinkMessage, NLM_F_DUMP, NLM_F_REQUEST,
    };
    use netlink_packet_route::{
        LinkMessage, RtnlMessage,
    };
    
  • figured out a Cargo.toml as follows (not really minimal, could not deactivate tokio_socket feature from netlink-proto as that removes new_connection() which the example uses):
    [package]
    name = "netlink-rs-notokio"
    version = "0.1.0"
    edition = "2018"
    
    [dependencies]
    futures = "0.3"
    async-std = { version = "1.12.0", features = ["attributes"] }
    netlink-proto = { version = "0.11.1" } #, default_features = false }
    netlink-packet-core = "0.5.0"
    netlink-packet-route = "0.15.0"
    

Note I also attempted to activate the smol_socket feature as the [[example]] section shows, but as the #[cfg(feature = "tokio_socket")] implies it does not help to get new_connection, tokio support not de-activatable (and it does not help with the error below).

Alas, it fails at runtime as follows:

$ RUST_BACKTRACE=1 ./target/debug/netlink-rs-notokio
thread 'main' panicked at 'there is no reactor running, must be called from the context of a Tokio 1.x runtime', /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/netlink-sys-0.8.4/src/tokio.rs:45:17
stack backtrace:
   0: rust_begin_unwind
             at /builddir/build/BUILD/rustc-1.67.1-src/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /builddir/build/BUILD/rustc-1.67.1-src/library/core/src/panicking.rs:64:14
   2: core::panicking::panic_display
             at /builddir/build/BUILD/rustc-1.67.1-src/library/core/src/panicking.rs:135:5
   3: tokio::runtime::scheduler::Handle::current
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/runtime/scheduler/mod.rs:191:13
   4: tokio::io::async_fd::AsyncFd<T>::with_interest
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/io/async_fd.rs:204:51
   5: tokio::io::async_fd::AsyncFd<T>::new
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.25.0/src/io/async_fd.rs:188:9
   6: <netlink_sys::tokio::TokioSocket as netlink_sys::async_socket::AsyncSocket>::new
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/netlink-sys-0.8.4/src/tokio.rs:45:17
   7: netlink_proto::connection::Connection<T,S,C>::new
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/netlink-proto-0.11.1/src/connection.rs:69:22
   8: netlink_proto::new_connection_with_codec
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/netlink-proto-0.11.1/src/lib.rs:284:9
   9: netlink_proto::new_connection
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/netlink-proto-0.11.1/src/lib.rs:239:5
  10: netlink_rs_notokio::main::main::{{closure}}
             at ./src/main.rs:22:33
  11: netlink_rs_notokio::main::{{closure}}
             at ./src/main.rs:18:1
  12: <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll::{{closure}}
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/builder.rs:199:17
  13: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::{{closure}}
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/task_locals_wrapper.rs:60:13
  14: std::thread::local::LocalKey<T>::try_with
             at /builddir/build/BUILD/rustc-1.67.1-src/library/std/src/thread/local.rs:446:16
  15: std::thread::local::LocalKey<T>::with
             at /builddir/build/BUILD/rustc-1.67.1-src/library/std/src/thread/local.rs:422:9
  16: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/task_locals_wrapper.rs:55:9
  17: <async_std::task::builder::SupportTaskLocals<F> as core::future::future::Future>::poll
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/builder.rs:197:13
  18: <futures_lite::future::Or<F1,F2> as core::future::future::Future>::poll
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-lite-1.12.0/src/future.rs:526:33
  19: async_executor::Executor::run::{{closure}}
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.5.0/src/lib.rs:237:31
  20: async_executor::LocalExecutor::run::{{closure}}
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.5.0/src/lib.rs:436:33
  21: async_io::driver::block_on
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-io-1.12.0/src/driver.rs:146:33
  22: async_global_executor::reactor::block_on::{{closure}}
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.3.1/src/reactor.rs:3:18
  23: async_global_executor::reactor::block_on
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.3.1/src/reactor.rs:12:5
  24: async_global_executor::executor::block_on::{{closure}}
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.3.1/src/executor.rs:26:36
  25: std::thread::local::LocalKey<T>::try_with
             at /builddir/build/BUILD/rustc-1.67.1-src/library/std/src/thread/local.rs:446:16
  26: std::thread::local::LocalKey<T>::with
             at /builddir/build/BUILD/rustc-1.67.1-src/library/std/src/thread/local.rs:422:9
  27: async_global_executor::executor::block_on
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-global-executor-2.3.1/src/executor.rs:26:5
  28: async_std::task::builder::Builder::blocking::{{closure}}::{{closure}}
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/builder.rs:171:25
  29: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current::{{closure}}
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/task_locals_wrapper.rs:60:13
  30: std::thread::local::LocalKey<T>::try_with
             at /builddir/build/BUILD/rustc-1.67.1-src/library/std/src/thread/local.rs:446:16
  31: std::thread::local::LocalKey<T>::with
             at /builddir/build/BUILD/rustc-1.67.1-src/library/std/src/thread/local.rs:422:9
  32: async_std::task::task_locals_wrapper::TaskLocalsWrapper::set_current
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/task_locals_wrapper.rs:55:9
  33: async_std::task::builder::Builder::blocking::{{closure}}
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/builder.rs:168:17
  34: std::thread::local::LocalKey<T>::try_with
             at /builddir/build/BUILD/rustc-1.67.1-src/library/std/src/thread/local.rs:446:16
  35: std::thread::local::LocalKey<T>::with
             at /builddir/build/BUILD/rustc-1.67.1-src/library/std/src/thread/local.rs:422:9
  36: async_std::task::builder::Builder::blocking
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/builder.rs:161:9
  37: async_std::task::block_on::block_on
             at /home/builder/.cargo/registry/src/github.com-1ecc6299db9ec823/async-std-1.12.0/src/task/block_on.rs:33:5
  38: netlink_rs_notokio::main
             at ./src/main.rs:18:1
  39: core::ops::function::FnOnce::call_once
             at /builddir/build/BUILD/rustc-1.67.1-src/library/core/src/ops/function.rs:507:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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