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

invalid ipv6 host #1739

Closed
LYF1999 opened this issue Mar 9, 2022 · 4 comments · Fixed by #1818
Closed

invalid ipv6 host #1739

LYF1999 opened this issue Mar 9, 2022 · 4 comments · Fixed by #1818
Labels
E-easy good first issue Good for newcomers

Comments

@LYF1999
Copy link

LYF1999 commented Mar 9, 2022

 let uri = "mysql://username:p@ssw0rd@[::1]:5432/database";
 let opts = MySqlConnectOptions::from_str(uri).unwrap();
 println!("{:?}", opts.host); // the opts.host is "[::1]"

sqlx try to use this host to connect at

None => Socket::connect_tcp(&options.host, options.port).await?,

but [::1] is a invalid address for tokio::net::TcpStream::connect, which expect a address like ::1 without a []
so, we will get an error failed to lookup address information: Name or service not known

@abonander
Copy link
Collaborator

abonander commented Mar 23, 2022

My question is: is this a url crate bug, a Tokio bug, or a SQLx bug?

@jplatte
Copy link
Contributor

jplatte commented Mar 23, 2022

I'm pretty sure this is a SQLx bug. The [] are part of a URL containing an IPv6 address, they're not part of the address itself. A type like IpAddr that this is likely parsed into internally won't have parsing code that expects [].

The url crate explicitly documents that the [] are part of the host string, though it's unfortunate that you can so easily shoot yourself in the foot because of that when using the crate.

@abonander
Copy link
Collaborator

So the fix here would be to just trim [] from the host string.

@abonander abonander added good first issue Good for newcomers E-easy labels Apr 6, 2022
@techytoes
Copy link

Hi @abonander, I would like to work on this issue if not already been taken. Also, I am new to this organization so can you please share more details regarding the issue. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants