nats-io / nats.rs

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

bug: `async_nats::connect` ignores all options in nats url #1341

Open haruki-nikaidou opened 1 week ago

haruki-nikaidou commented 1 week ago

Observed behavior

async_nats::connect ignores all options in nats url and use default options

Expected behavior

parse options from url

Server and client version

bug is in crate async-nats 0.37.0

Host environment

No response

Steps to reproduce

The bug is very obvious in the source code:

in lib.rs L1113

pub async fn connect<A: ToServerAddrs>(addrs: A) -> Result<Client, ConnectError> {
    connect_with_options(addrs, ConnectOptions::default()).await
}

And according to lib.rs L932~L1022, connect_with_options use option in argument to override the options in url. So connect ignore all options in url.

reproduce:

#[cfg(test)]
mod test {
    #[tokio::test]
    async fn test_nats_url_parse() {
        const URL: &str = "nats://yourusername:password@example.domain.com:4222";
        let _ = async_nats::connect(URL).await.unwrap();  
    }
}
Jarema commented 1 week ago

Thanks for reporting.

This is true, however I would advise using ConnectOptions for setting up credentials - especially if you pass in multiple servers.

There is also #1193 that would need to be fix for that to work.

This can be of course fixed, but is a pretty low priority considering not being the most optimal way to pass credentials to the client.

Are you maybe interested in contributing?