Skip to content

abstract namespace unix sockets fail in hostname lookup #1240

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

Open
jayvdb opened this issue May 18, 2025 · 1 comment
Open

abstract namespace unix sockets fail in hostname lookup #1240

jayvdb opened this issue May 18, 2025 · 1 comment

Comments

@jayvdb
Copy link

jayvdb commented May 18, 2025

According to https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-PARAMKEYWORDS

If the host name starts with @, it is taken as a Unix-domain socket in the abstract namespace (currently supported on Linux and Windows).

However tokio-posgres connect prevents host=@... ; the error is

called Result::unwrap() on an Err value: Custom { kind: Uncategorized, error: "failed to lookup address information: Name or service not known" }

And the backtrace points to this line https://github.com/sfackler/rust-postgres/blob/02463b1/tokio-postgres/src/connect.rs#L98

@jayvdb
Copy link
Author

jayvdb commented May 31, 2025

Note tokio doesnt support this tokio-rs/tokio#4610

I was able to workaround this using the suggestions there, ending up with

           let socket = if path.display().to_string().starts_with('@') {
                // #[cfg(target_os = "linux")]
                let addr = SocketAddr::from_abstract_name(path.as_os_str().as_encoded_bytes()).unwrap();
                eprintln!("Connecting to abstract Unix socket: {addr:?}");
                let std_stream = std::os::unix::net::UnixStream::connect_addr(&addr).unwrap();
                let stream = UnixStream::from_std(std_stream.into());
                connect_with_timeout(async { stream }, connect_timeout).await.unwrap()
            }
            else {
                connect_with_timeout(UnixStream::connect(path), connect_timeout).await.unwrap()
            };

But then I get connection refused

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

1 participant