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

client: support other async runtimes than tokio #1335

Open
gcp-development opened this issue Mar 29, 2024 · 2 comments
Open

client: support other async runtimes than tokio #1335

gcp-development opened this issue Mar 29, 2024 · 2 comments

Comments

@gcp-development
Copy link

Hello,

I am having this weird error a due the use of tokio out of context for the "WsTransportClientBuilder".

thread 'main' panicked at /.cargo/git/checkouts/jsonrpsee-b50257996090af44/658afa5/client/transport/src/ws/mod.rs:480:19:
there is no reactor running, must be called from the context of a Tokio 1.x runtime
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Is this because of the async_io ?

fn main() -> anyhow::Result<()> {
    esp_idf_svc::sys::link_patches();
    esp_idf_svc::log::EspLogger::initialize_default();

    let mut root_store = rustls::RootCertStore::empty();
    root_store.roots = webpki_roots::TLS_SERVER_ROOTS.iter().cloned().collect();
    let app_config = CONFIG;

    async_io::block_on(async move {
        let _wifi = connect_wifi(app_config.wifi_ssid, app_config.wifi_psk);
        let (sender, receiver) = WsTransportClientBuilder::default()
            .use_webpki_rustls()
            .build(Url::parse("wss://rococo-contracts-rpc.polkadot.io:443").unwrap())
            .await.expect("TODO: panic message");

        Result::<_, anyhow::Error>::Ok(())
    });

    Ok(())
}

cargo.toml

(...)
jsonrpsee = { version = "0.22.3", default-features = false, features = ["client-ws-transport-webpki-tls"] }
async-io = "2.3.2"
(...)
@niklasad1
Copy link
Member

Is this because of the async_io ?

Yes, jsonrpsee is tightly-coupled to tokio and requires the tokio runtime to be initialized because it's using tokio::spawn under the hood to spawn the background task.

Can't use tokio on your platform or what's the reason to use async-io crate?

@gcp-development
Copy link
Author

gcp-development commented Mar 30, 2024

Hi @niklasad1,

Thank you for your answer.

when you work in embedded systems "every little byte helps". Tokio is a very good crate but is too fat when compared with async-io.

For instance for this case above(STD/ESP-IDF framework) we would need to use OpenThread with unsafe code instructions like "esp_vfs_eventfd_register()". And we would need to reorganize the partition-tables in order to work with Tokio.

Cheers,

@niklasad1 niklasad1 changed the title there is no reactor running, must be called from the context of a Tokio 1.x runtime-[xtensa-esp32s3-espidf] client: support other async runtimes than tokio Apr 2, 2024
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