Very strange InvalidDNSNameError with query! macro
I have installed sqlx 0.5.1 with the features ["runtime-tokio-rustls", "macro", "postgres"] on Windows 10 (Build 21332.1000) with Rust stable 1.50.0.
However using sqlx::query!("SELECT opt FROM users WHERE id = $1 limit 1", msg.author.id) will cause this very strange compiler error to appear:
error: error occurred while attempting to establish a TLS connection: InvalidDNSNameError
--> src\commands\config.rs:13:15
|
13 | let opt = sqlx::query!("SELECT opt FROM users WHERE id = $1", msg.author.id).fetch_one(pool).await?;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
I'm new to sqlx (and rusty with sql in general, pun not intended), so hopefully this isn't just something to do with syntax.
Seems I just needed to encapsulate my ip with [brackets] in my DATABASE_URL. Weird how compilation was affected as well though.
Actually, for some reason it does not work with an IPv4 address: Configuration(InvalidIpv6Address) when using URL postgres://test:passwd@[192.168.29.231]/test
#846 describes this issue, but only for MySQL. Should this issue be closed and the original issue be edited to include PostgreSQL as well?
This is simply a consequence of rustls not supporting IP addresses. There may be a way to disable TLS support through the connection string so rustls never tries to resolve the IP as a DNS name.
Alternatively you could switch to the native-tls TLS backend.
for postgres switch to runtime-tokio-native-tls on your cargo.toml and remove the brackets from your ip and remove the port, that worked for me. postgres://user:[email protected]/database
it seems it is complicate to switch to native-tls runtime because other pacakge's dependency. i go with create a domain DNS record for the IP and it worked.
seem, I replaced IPv4 address to hostname, it's works.
DATABASE_URL=postgres://p9s:123456@localhost:5432/mydb <---- this ok DATABASE_URL=postgres://p9s:[email protected]:5432/mydb <---- not work
@kotx this should work with a more recent version of rustls. We've managed to upgrade and connect via IP address.
@kotx this should work with a more recent version of rustls. We've managed to upgrade and connect via IP address.
Seems to work with some very basic testing from my side, thanks! If everybody else still runs into this issue please let me know and I can reopen.