nats-io / nats.rs

Rust client for NATS, the cloud native messaging system.
Apache License 2.0
1.07k stars 169 forks source link

async-nats connect error "failed to read root certificates: MissingOrMalformedExtensions" #789

Open ronz-sensible opened 1 year ago

ronz-sensible commented 1 year ago

Connect to local nats server failure.

NATS version

name = "nats" version = "0.16.0" name = "nats" version = "0.23.1"

rustc version

rustc 1.65.0 (897e37553 2022-11-02)

OS/Container environment:

Edition Windows 11 Pro Version 21H2 OS build 22000.1335 Experience Windows Feature Experience Pack 1000.22000.1335.0

Steps or code to reproduce the issue:

  1. install the latest nats-server locally

  2. run it without any flag: nats-server.exe

  3. verify that nats-cli connect successfully using for example: nats --server=nats://0.0.0.0:4222 sub foo and nats --server=nats://0.0.0.0:4222 pub foo --count 10 "Message {{Count}} @ {{Time}}"

  4. write this code in some unit test (I did it in async-nats\tests\client_tests.rs)

    [tokio::test]

    async fn connect_to_local_natsserver() { = async_nats::connect("nats://0.0.0.0:4222").await.unwrap(); }

  5. RUST_BACKTRACE=1 cargo test connect_to_local_nats_server

Expected result:

Connect successfully

Actual result:

---- client::connect_to_local_nats_server stdout ---- thread 'client::connect_to_local_nats_server' panicked at 'called Result::unwrap() on an Err value: Custom { kind: Other, error: "failed to read root certificates: MissingOrMalformedExtensions" }', async-nats\tests\client_tests.rs:27:62 stack backtrace: 0: std::panicking::begin_panic_handler at /rustc/897e37553bba8b42751c67658967889d11ecd120/library\std\src\panicking.rs:584 1: core::panicking::panic_fmt at /rustc/897e37553bba8b42751c67658967889d11ecd120/library\core\src\panicking.rs:142 2: core::result::unwrap_failed at /rustc/897e37553bba8b42751c67658967889d11ecd120/library\core\src\result.rs:1785 3: enum2$<core::result::Result<async_nats::client::Client,std::io::error::Error> >::unwrap<async_nats::client::Client,std::io::error::Error> at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\result.rs:1107 4: client_tests::client::connect_to_local_nats_server::async_block$0 at .\tests\client_tests.rs:27 5: core::future::from_generator::impl$1::poll<enum2$<client_tests::client::connect_to_local_nats_server::async_block_env$0> > at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\mod.rs:91 6: core::future::future::impl$1::poll<ref_mut$<core::future::from_generator::GenFuture<enum2$<client_tests::client::connect_to_local_nats_server::async_block_env$0> > > > at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\future\future.rs:124 7: tokio::runtime::scheduler::current_thread::impl$9::block_on::closure$0::closure$0::closure$0<core::pin::Pin<ref_mut$<core::future::from_generator::GenFuture<enum2$<client_tests::client::connect_to_local_nats_server::async_block_env$0> > > > > at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\runtime\scheduler\current_thread.rs:525 8: tokio::coop::with_budget::closure$0<enum2$<core::task::poll::Poll<tuple$<> > >,tokio::runtime::scheduler::current_thread::impl$9::block_on::closure$0::closure$0::closure_env$0<core::pin::Pin<ref_mut$<core::future::from_generator::GenFuture<enum2$<client_t at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\coop.rs:102 9: std::thread::local::LocalKey<core::cell::Cell >::try_with<core::cell::Cell,tokio::coop::with_budget::closure_env$0<enum2$<core::task::poll::Poll<tuple$<> > >,tokio::runtime::scheduler::current_thread::impl$9::bloc at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\std\src\thread\local.rs:445 10: std::thread::local::LocalKey<core::cell::Cell >::with<core::cell::Cell,tokio::coop::with_budget::closure_env$0<enum2$<core::task::poll::Poll<tuple$<> > >,tokio::runtime::scheduler::current_thread::impl$9::block_on at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\std\src\thread\local.rs:421 11: tokio::coop::with_budget at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\coop.rs:95 12: tokio::coop::budget at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\coop.rs:72 13: tokio::runtime::scheduler::current_thread::impl$9::block_on::closure$0::closure$0<core::pin::Pin<ref_mut$<core::future::from_generator::GenFuture<enum2$<client_tests::client::connect_to_local_nats_server::async_block_env$0> > > > > at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\runtime\scheduler\current_thread.rs:525 14: tokio::runtime::scheduler::current_thread::Context::enter<enum2$<core::task::poll::Poll<tuple$<> > >,tokio::runtime::scheduler::current_thread::impl$9::block_on::closure$0::closure_env$0<core::pin::Pin<ref_mut$<core::future::from_generator::GenFuture<enum at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\runtime\scheduler\current_thread.rs:349 15: tokio::runtime::scheduler::current_thread::impl$9::block_on::closure$0<core::pin::Pin<ref_mut$<core::future::from_generator::GenFuture<enum2$<client_tests::client::connect_to_local_nats_server::async_block_env$0> > > > > at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\runtime\scheduler\current_thread.rs:524 16: tokio::runtime::scheduler::current_thread::impl$9::enter::closure$0<tokio::runtime::scheduler::current_thread::impl$9::block_on::closure_env$0<core::pin::Pin<ref_mut$<core::future::from_generator::GenFuture<enum2$<client_tests::client::connect_to_local_na at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\runtime\scheduler\current_thread.rs:595 17: tokio::macros::scoped_tls::ScopedKey::set<tokio::runtime::scheduler::current_thread::Context,tokio::runtime::scheduler::current_thread::impl$9::enter::closure_env$0<tokio::runtime::scheduler::current_thr at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\macros\scoped_tls.rs:61 18: tokio::runtime::scheduler::current_thread::CoreGuard::enter<tokio::runtime::scheduler::current_thread::impl$9::block_on::closure_env$0<core::pin::Pin<ref_mut$<core::future::from_generator::GenFuture<enum2$<client_tests::client::connect_to_local_nats_serve at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\runtime\scheduler\current_thread.rs:595 19: tokio::runtime::scheduler::current_thread::CoreGuard::block_on<core::pin::Pin<ref_mut$<core::future::from_generator::GenFuture<enum2$<client_tests::client::connect_to_local_nats_server::async_block_env$0> > > > > at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\runtime\scheduler\current_thread.rs:515 20: tokio::runtime::scheduler::current_thread::CurrentThread::block_on<core::future::from_generator::GenFuture<enum2$<client_tests::client::connect_to_local_nats_server::async_block_env$0> > > at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\runtime\scheduler\current_thread.rs:161 21: tokio::runtime::Runtime::block_on<core::future::from_generator::GenFuture<enum2$<client_tests::client::connect_to_local_nats_server::async_block_env$0> > >
at C:\Users\ron.z.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.21.2\src\runtime\mod.rs:490 22: client_tests::client::connect_to_local_nats_server at .\tests\client_tests.rs:27 23: client_tests::client::connect_to_local_nats_server::closure$0 at .\tests\client_tests.rs:26 24: core::ops::function::FnOnce::call_once<client_tests::client::connect_to_local_nats_server::closure_env$0,tuple$<> > at /rustc/897e37553bba8b42751c67658967889d11ecd120\library\core\src\ops\function.rs:248 25: core::ops::function::FnOnce::call_once at /rustc/897e37553bba8b42751c67658967889d11ecd120/library\core\src\ops\function.rs:248 note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

failures: client::connect_to_local_nats_server

ronz-sensible commented 1 year ago

Test it again on another machine: rust version 1.66.0 main branch did not throw the same original error but only the latest that arrive after this fix Err value: Os { code: 10049, kind: AddrNotAvailable, message: "The requested address is not valid in its context." }' nats-cli test passed as before with the same address.

OS: Windows 11 Home, version 22H2

ronz-sensible commented 1 year ago

Run the same test on the original machine after update to rust 1.66.0, same results as before.

ronz-sensible commented 1 year ago

The fix work well. after changing the test to connect to nats://127.0.0.1:4222