You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UnixStream doesn't support abstract addresses #42048
Linux's abstract namespace is not supported. Functionality may be added in the future via extension traits in std::os::linux::net.
This feature is described in the Linux unix(7) manpage.
This issue tracks the absence of (and hopefully future development of) this feature.
Reacted by Alex Gaynor, Tom, Todd Stellanova, Zeeshan Ali Khan, Emill, Gamadril, Daniil Bondarev, Brandon Thomas, Yerkebulan Tulibergenov, Sebastian Dröge and 1 more
Not that easy... I'd probably want to change UnixStream::connect to take a A: Into<SocketAddr> and then impl<T: AsRef<Path>> From<T> for SocketAddr. But, that conversion is fallible (see std::sys::unix::ext::sockaddr_un). So you need TryInto. But then you can't supply a SocketAddr directly until we get impl<T, U> TryFrom<U> for T where T: From<U>, which requires !...
That seems like a strange API, to have two different connect functions. You can have it be Linux only to have an extension trait to create a SockAddr on Linux only.
How is that valuable in any way in practice? When have you ever said, "man, this code I'm trying to write would have been way better if some_socket_addr.to_socket_addrs() returned a Result<T, !> instead of Result<T, io::Error>"? If you're working in a concrete context you're not going to use try_from to go from a type to itself, and if you're in an generic context, you're only going use try_from if you want to deal with the failure case anyway.
I'd advice against using that misfeature. In the past 20 years, I've never seen any practical usecase
for that, and it creates more trouble than it's actually worth it.
Reacted by kennytm, jethrogb, Mickaël Salaün, Tom, Todd Stellanova, Matthew Fisher, Josh Triplett, Gamadril, Daniil Bondarev, Scott Olson and 2 more
I would love to see a PR implementing Linux-only support for abstract addresses. I believe we will be able to reach agreement in the PR without needing to draft an RFC.
Now that TryFrom and never_type are close to being stabilized, I took another look at this. d47e979
There's a conflicting implementations issue, a P: AsRef<Path> might already implement Into<SocketAddr>:
error[E0119]: conflicting implementations of trait `core::convert::TryFrom<_>` for type `sys::unix::ext::net::SocketAddr`:
--> src/libstd/sys/unix/ext/net.rs:91:1
|
91 | impl<P: AsRef<Path>> TryFrom<P> for SocketAddr {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: conflicting implementation in crate `core`:
- impl<T, U> core::convert::TryFrom<U> for T
where U: core::convert::Into<T>;
Rather than changing the type of connect (which seems likely to produce inference errors), why not introduce a couple of new methods, bind_addr and connect_addr, which accept a concrete SocketAddr? Those methods could exist on all platforms; only the mechanism to create an abstract SocketAddr needs to be a platform-specific extension.
This would avoid dealing with TryFrom at all, and would avoid introducing potential inference and compatibility issues as well.
I'd like to chime in on this one. There's one neat use case of the abstract namespace and it's implementing robust lock against running in parallel. You try to bind the address and if it's already in use, some other instance is running. Furthermore, unlike the filesystem based ones, these clean up automatically and you don't have to worry about races around unlinking the old (dead) socket „file“.
Activity
sfackler commentedon May 17, 2017
This should be pretty easy to add for anyone that's interested!
jethrogb commentedon May 17, 2017
Not that easy... I'd probably want to change
UnixStream::connectto take aA: Into<SocketAddr>and thenimpl<T: AsRef<Path>> From<T> for SocketAddr. But, that conversion is fallible (seestd::sys::unix::ext::sockaddr_un). So you needTryInto. But then you can't supply aSocketAddrdirectly until we getimpl<T, U> TryFrom<U> for T where T: From<U>, which requires!...sfackler commentedon May 17, 2017
Abstract namespaces are Linux only so we'd only want to make them available through a Linux-only method. Probably something like
jethrogb commentedon May 17, 2017
That seems like a strange API, to have two different connect functions. You can have it be Linux only to have an extension trait to create a SockAddr on Linux only.
sfackler commentedon May 17, 2017
Why is it impossible to implement
TryFromfrom a type to itself without!?retep998 commentedon May 17, 2017
@sfackler Because we want to indicate that the
TryFromimplementation will never fail, so gotta wait until!is available.jethrogb commentedon May 17, 2017
Actually that might still not work, because now you need
TryFrom<Err=io::Error>forAsRef<Path>andTryFrom<Err=!>forSocketAddr...sfackler commentedon May 17, 2017
@retep998
!is not the only way to indicate that.String'sFromStrimpl has always been infallible: https://doc.rust-lang.org/src/collections/string.rs.html#1829-1852some_socket_addr.to_socket_addrs()returned aResult<T, !>instead ofResult<T, io::Error>"? If you're working in a concrete context you're not going to usetry_fromto go from a type to itself, and if you're in an generic context, you're only going usetry_fromif you want to deal with the failure case anyway.metux commentedon Jul 12, 2017
I'd advice against using that misfeature. In the past 20 years, I've never seen any practical usecase
for that, and it creates more trouble than it's actually worth it.
jethrogb commentedon Jul 12, 2017
@metux practical use-case is interoperability with other software that creates an abstract socket?
metux commentedon Jul 13, 2017
Ok. Does anyone here run an application which needs that ? I don't recall any in the last two decades.
jethrogb commentedon Jul 13, 2017
Would I have opened this ticket if I didn't?
2 remaining items
dtolnay commentedon Nov 17, 2017
I would love to see a PR implementing Linux-only support for abstract addresses. I believe we will be able to reach agreement in the PR without needing to draft an RFC.
jethrogb commentedon Dec 21, 2018
Now that
TryFromandnever_typeare close to being stabilized, I took another look at this. d47e979There's a conflicting implementations issue, a
P: AsRef<Path>might already implementInto<SocketAddr>:jethrogb commentedon Dec 21, 2018
Here is the commit that adds
SocketAddrExtc4db068. That should plug right into whatever solution we come up with for the UnixStream API.joshtriplett commentedon Jan 26, 2020
I'm interested in this support.
Rather than changing the type of
connect(which seems likely to produce inference errors), why not introduce a couple of new methods,bind_addrandconnect_addr, which accept a concreteSocketAddr? Those methods could exist on all platforms; only the mechanism to create an abstractSocketAddrneeds to be a platform-specific extension.This would avoid dealing with
TryFromat all, and would avoid introducing potential inference and compatibility issues as well.vorner commentedon Jan 28, 2020
I'd like to chime in on this one. There's one neat use case of the abstract namespace and it's implementing robust lock against running in parallel. You try to bind the address and if it's already in use, some other instance is running. Furthermore, unlike the filesystem based ones, these clean up automatically and you don't have to worry about races around unlinking the old (dead) socket „file“.
toshokan commentedon Oct 13, 2020
Sockets with abstract addresses are also often needed to interact with dbus on Linux.
See https://github.com/diwic/dbus-rs/blob/627b42597f13c8f5db3b4259271a5881439c310b/dbus-native/src/sys.rs#L8
Rollup merge of rust-lang#85379 - mdaverde:uds-abstract, r=joshtriplett
Rollup merge of rust-lang#85379 - mdaverde:uds-abstract, r=joshtriple…
Auto merge of rust-lang#85379 - mdaverde:uds-abstract, r=joshtriplett
Thomasdezeeuw commentedon Dec 24, 2023
This is now possible by using the
std::os::linux::net::SocketAddrExttrait to create abstract namespace addresses and then usingstd::os::unix::net::UnixStream::connect_addr.