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

Merge 1.39.x to master #6787

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:

```toml
[dependencies]
tokio = { version = "1.39.2", features = ["full"] }
tokio = { version = "1.39.3", features = ["full"] }
```
Then, on your main.rs:

Expand Down
7 changes: 7 additions & 0 deletions tokio/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.39.3 (August 17th, 2024)

This release fixes a regression where the unix socket api stopped accepting
the abstract socket namespace. ([#6772])

[#6772]: https://github.com/tokio-rs/tokio/pull/6772

# 1.39.2 (July 27th, 2024)

This release fixes a regression where the `select!` macro stopped accepting
Expand Down
2 changes: 1 addition & 1 deletion tokio/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "tokio"
# - README.md
# - Update CHANGELOG.md.
# - Create "v1.x.y" git tag.
version = "1.39.2"
version = "1.39.3"
edition = "2021"
rust-version = "1.70"
authors = ["Tokio Contributors <team@tokio.rs>"]
Expand Down
2 changes: 1 addition & 1 deletion tokio/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Make sure you activated the full features of the tokio crate on Cargo.toml:

```toml
[dependencies]
tokio = { version = "1.39.2", features = ["full"] }
tokio = { version = "1.39.3", features = ["full"] }
```
Then, on your main.rs:

Expand Down
23 changes: 21 additions & 2 deletions tokio/src/net/unix/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@ use crate::net::unix::{SocketAddr, UnixStream};

use std::fmt;
use std::io;
#[cfg(target_os = "android")]
use std::os::android::net::SocketAddrExt;
#[cfg(target_os = "linux")]
use std::os::linux::net::SocketAddrExt;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::unix::ffi::OsStrExt;
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
use std::os::unix::net;
use std::os::unix::net::{self, SocketAddr as StdSocketAddr};
use std::path::Path;
use std::task::{Context, Poll};

Expand Down Expand Up @@ -70,7 +76,20 @@ impl UnixListener {
where
P: AsRef<Path>,
{
let listener = mio::net::UnixListener::bind(path)?;
// For now, we handle abstract socket paths on linux here.
#[cfg(any(target_os = "linux", target_os = "android"))]
let addr = {
let os_str_bytes = path.as_ref().as_os_str().as_bytes();
if os_str_bytes.starts_with(b"\0") {
StdSocketAddr::from_abstract_name(os_str_bytes)?
} else {
StdSocketAddr::from_pathname(path)?
}
};
#[cfg(not(any(target_os = "linux", target_os = "android")))]
let addr = StdSocketAddr::from_pathname(path)?;

let listener = mio::net::UnixListener::bind_addr(&addr)?;
let io = PollEvented::new(listener)?;
Ok(UnixListener { io })
}
Expand Down
23 changes: 21 additions & 2 deletions tokio/src/net/unix/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@ use crate::net::unix::SocketAddr;
use std::fmt;
use std::io::{self, Read, Write};
use std::net::Shutdown;
#[cfg(target_os = "android")]
use std::os::android::net::SocketAddrExt;
#[cfg(target_os = "linux")]
use std::os::linux::net::SocketAddrExt;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::unix::ffi::OsStrExt;
use std::os::unix::io::{AsFd, AsRawFd, BorrowedFd, FromRawFd, IntoRawFd, RawFd};
use std::os::unix::net;
use std::os::unix::net::{self, SocketAddr as StdSocketAddr};
use std::path::Path;
use std::pin::Pin;
use std::task::{Context, Poll};
Expand Down Expand Up @@ -66,7 +72,20 @@ impl UnixStream {
where
P: AsRef<Path>,
{
let stream = mio::net::UnixStream::connect(path)?;
// On linux, abstract socket paths need to be considered.
#[cfg(any(target_os = "linux", target_os = "android"))]
let addr = {
let os_str_bytes = path.as_ref().as_os_str().as_bytes();
if os_str_bytes.starts_with(b"\0") {
StdSocketAddr::from_abstract_name(os_str_bytes)?
} else {
StdSocketAddr::from_pathname(path)?
}
};
#[cfg(not(any(target_os = "linux", target_os = "android")))]
let addr = StdSocketAddr::from_pathname(path)?;

let stream = mio::net::UnixStream::connect_addr(&addr)?;
let stream = UnixStream::new(stream)?;

poll_fn(|cx| stream.io.registration().poll_write_ready(cx)).await?;
Expand Down
13 changes: 13 additions & 0 deletions tokio/tests/uds_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,3 +420,16 @@ async fn epollhup() -> io::Result<()> {
);
Ok(())
}

// test for https://github.com/tokio-rs/tokio/issues/6767
#[tokio::test]
#[cfg(any(target_os = "linux", target_os = "android"))]
async fn abstract_socket_name() {
let socket_path = "\0aaa";
let listener = UnixListener::bind(socket_path).unwrap();

let accept = listener.accept();
let connect = UnixStream::connect(&socket_path);

try_join(accept, connect).await.unwrap();
}
Loading