Skip to content

7782: Support as many abstract datagram unix domain socket operations as possible#75

Open
martin-augment wants to merge 3 commits intomasterfrom
pr-7782-2026-03-09-10-53-18
Open

7782: Support as many abstract datagram unix domain socket operations as possible#75
martin-augment wants to merge 3 commits intomasterfrom
pr-7782-2026-03-09-10-53-18

Conversation

@martin-augment
Copy link
Copy Markdown
Owner

7782: To review by AI

ntninja and others added 3 commits January 6, 2026 17:54
Deduplicates the path2socket logic into our `SocketAddr` constructor. Where MIO
currently doesn’t support using a STD Unix SocketAddr, a warning for this
inconsistent behaviour is added to the documentation.
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 9, 2026

Walkthrough

The changes introduce a centralized SocketAddr::from_path constructor to handle Unix domain socket path-to-address conversion across multiple modules. Runtime validation is added on Linux/Android targets to reject abstract Unix socket paths (those starting with NUL bytes) before I/O operations. Several modules consolidate their platform-specific path handling to use this new constructor, reducing conditional compilation blocks. Documentation sections describing limitations with abstract namespace paths are added to affected public methods. Tests verify behavior on Linux/Android platforms. The public API surface remains unchanged.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pr-7782-2026-03-09-10-53-18

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances Tokio's support for abstract Unix domain sockets, primarily on Linux and Android. It centralizes the logic for parsing socket addresses, including abstract paths, into a dedicated SocketAddr::from_path function. While improving consistency, it also explicitly identifies and documents current limitations where abstract paths are not yet fully supported for certain datagram operations, providing clear guidance and FIXME markers for future development.

Highlights

  • Centralized Abstract Path Handling: The logic for parsing Unix domain socket addresses, including abstract paths on Linux/Android, has been centralized into a new SocketAddr::from_path function, improving consistency across UnixDatagram, UnixListener, and UnixStream.
  • Explicit Limitations for Datagram Operations: Explicit checks and FIXME comments were added to UnixDatagram's connect, try_send_to, send_to, and poll_send_to methods, indicating that abstract paths are currently unsupported for these operations due to underlying MIO limitations.
  • Documentation Updates: Documentation for UnixDatagram methods (connect, try_send_to, send_to, poll_send_to) was updated to clearly state the current limitations regarding abstract namespace paths.
  • New Test Case for Abstract Sockets: A new test case, recv_abstract, was added to uds_datagram.rs to verify the binding and receiving of messages from abstract Unix domain sockets on Linux/Android.
Changelog
  • tokio/src/net/unix/datagram/socket.rs
    • Added OsStrExt import for abstract path handling.
    • Modified bind to use SocketAddr::from_path.
    • Added Limitations section to connect documentation.
    • Implemented abstract path check and error return in connect.
    • Added Limitations section to try_send_to documentation.
    • Implemented abstract path check and error return in try_send_to.
    • Added Limitations section to send_to documentation.
    • Implemented abstract path check and error return in send_to.
    • Added Limitations section to poll_send_to documentation.
    • Implemented abstract path check and error return in poll_send_to.
  • tokio/src/net/unix/listener.rs
    • Removed platform-specific SocketAddrExt and OsStrExt imports.
    • Refactored bind to use SocketAddr::from_path for address parsing.
  • tokio/src/net/unix/socketaddr.rs
    • Added necessary imports for io, SocketAddrExt, and OsStrExt.
    • Introduced SocketAddr::from_path to encapsulate abstract and pathname socket address parsing.
  • tokio/src/net/unix/stream.rs
    • Removed platform-specific SocketAddrExt and OsStrExt imports.
    • Refactored connect to use SocketAddr::from_path for address parsing.
  • tokio/tests/uds_datagram.rs
    • Added SocketAddrExt and std_net imports for abstract socket testing.
    • Implemented recv_abstract test case to verify abstract Unix domain socket binding and message reception.
Activity
  • The pull request was created and is awaiting review.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@claude
Copy link
Copy Markdown

claude bot commented Mar 9, 2026

Code Review

Overall this is a clean refactor. Consolidating abstract socket path logic into SocketAddr::from_path eliminates real duplication across listener.rs, stream.rs, and datagram/socket.rs. The FIXME comments are appropriate and clearly document the limitations pending upstream MIO support.

Bug: Incorrect Android import in test file

In tokio/tests/uds_datagram.rs the test imports std::os::linux::net::SocketAddrExt for both Linux and Android. However std::os::linux does not exist on Android, so this would cause a compile failure on Android targets. The correct pattern (already used in socketaddr.rs lines 3-6 and 73-76) is separate cfg attributes for each OS, importing std::os::android::net::SocketAddrExt on Android and std::os::linux::net::SocketAddrExt on Linux.

Error kind inconsistency

The abstract-path guards added to connect, try_send_to, send_to, and poll_send_to all return io::ErrorKind::Other. io::ErrorKind::InvalidInput is more appropriate since the caller passed an invalid argument. This would also be consistent with what the non-Linux branch of the recv_abstract test already asserts (Some(io::ErrorKind::InvalidInput)).

Avoid suppressing bool_assert_comparison lint

The test uses #[allow(clippy::bool_assert_comparison)] alongside assert_eq!(addr.is_unnamed(), true). Use assert!(addr.is_unnamed()) directly instead of suppressing the lint.

SocketAddr::from_path documentation

from_path is now public API (re-exported via pub use socketaddr::SocketAddr). The current doc comment is minimal. It should include a # Errors section (describing failure conditions such as interior null bytes or abstract paths on non-Linux) and a # Examples block, consistent with the rest of the public API.

Missing tests for send-path rejection

The new test covers bind + recv_from on abstract sockets, and bind rejection on non-Linux. There are no tests for the rejection logic added to connect, send_to, and try_send_to on Linux. A test asserting these return an error for abstract paths would prevent silent regressions when the FIXME is addressed and the guard is removed.

Minor: .0 field access

let addr = SocketAddr::from_path(path)?.0; accesses the pub(super) inner field directly. A small pub(crate) fn into_std(self) accessor on SocketAddr would make the call sites clearer. Minor style point only.


Summary: The refactor direction is right and the overall quality is good. The Android import is the only issue that would cause a build failure; the rest are quality and consistency improvements worth addressing before merge.

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Mar 9, 2026

🤖 Augment PR Summary

Summary: Extends Tokio’s Unix datagram support to handle Linux/Android abstract-namespace addresses where possible.

Changes:

  • Added `SocketAddr::from_path` to parse filesystem vs. abstract (leading \0) Unix socket paths on Linux/Android.
  • Updated UnixListener::bind, UnixStream::connect, and UnixDatagram::bind to use address-based mio APIs (*_addr) via the new helper.
  • Documented and enforced current limitations: UnixDatagram::{connect, try_send_to, send_to, poll_send_to} still reject abstract paths (pending mio support) to avoid silently mis-handling \0-prefixed paths.
  • Added a Linux/Android test that binds a Tokio UnixDatagram in the abstract namespace and verifies it can receive a datagram sent via the stdlib.

Technical Notes: Abstract namespace support is currently asymmetric (bind/recv works; connect/send is explicitly rejected) and centralized path parsing reduces duplicated OS-specific logic.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

use std::io;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::linux::net::SocketAddrExt;
#[cfg(any(target_os = "linux", target_os = "android"))]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[cfg(any(target_os = "linux", target_os = "android"))] combined with std::os::linux::net::SocketAddrExt is not portable: on Android the extension trait is under std::os::android::net, so this import will fail to compile for target_os = "android".

Severity: high

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Augment AI reviewer is correct! The IT test should use one import for Linux and a different one for Android. Since the IT tests are executed only on Linux in the Github Actions CI environment there is no issue at the moment because it is always Linux and the imported file matches the OS. A problem would occur when someone tries to run the test on Android.

/// a socket path within the abstract namespace.
pub fn from_path<P>(path: P) -> io::Result<Self>
where
P: AsRef<Path>,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc for SocketAddr::from_path says “On Linux …”, but the implementation is enabled for target_os = "android" as well (cfg(any(linux, android))), which makes the docs/intent slightly misleading.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Augment AI reviewer is correct! The method is available for both Linux and Android (Android is based on Linux but still there are differences), so the documentation should be more explicit that Android is also supported.

if target.as_ref().as_os_str().as_bytes().starts_with(b"\0") {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
"UnixDatagram::send_to(): abstract paths currently unsupported",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In poll_send_to, the error string says UnixDatagram::send_to() even though the check is in poll_send_to, which could be confusing when diagnosing failures from this API.

Severity: low

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Augment AI reviewer is correct! The error message is copy/pasted from another method and the method name is still mentioning the source of the copy. The method name should be updated to "poll_send_to()" to avoid confusion in the developer debugging an issue.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

use std::future::poll_fn;
use std::io;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::linux::net::SocketAddrExt;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong platform import for Android in test file

Medium Severity

The import std::os::linux::net::SocketAddrExt is gated behind cfg(any(target_os = "linux", target_os = "android")), but std::os::linux only exists on Linux — not Android. This will fail to compile when targeting Android. The correct pattern (used in socketaddr.rs and uds_stream.rs) uses separate cfg attributes: #[cfg(target_os = "android")] use std::os::android::net::SocketAddrExt and #[cfg(target_os = "linux")] use std::os::linux::net::SocketAddrExt.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Bugbot AI reviewer is correct! The IT test should use one import for Linux and a different one for Android. Since the IT tests are executed only on Linux in the Github Actions CI environment there is no issue at the moment because it is always Linux and the imported file matches the OS. A problem would occur when someone tries to run the test on Android.

if target.as_ref().as_os_str().as_bytes().starts_with(b"\0") {
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
"UnixDatagram::send_to(): abstract paths currently unsupported",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message references wrong method name in poll_send_to

Low Severity

The error message in poll_send_to says "UnixDatagram::send_to()" instead of "UnixDatagram::poll_send_to()". All other methods in this file include the correct method name in their error messages (connectconnect(), try_send_totry_send_to()), so this appears to be a copy-paste oversight that could confuse users debugging the error.

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Bugbot AI reviewer is correct! The error message is copy/pasted from another method and the method name is still mentioning the source of the copy. The method name should be updated to "poll_send_to()" to avoid confusion in the developer debugging an issue.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for abstract Unix domain socket paths for datagrams, primarily by refactoring path-to-address conversion into a new SocketAddr::from_path method. This is a clean and effective way to centralize the logic. The changes also correctly add temporary blocks in connect and send_to variants to prevent usage with abstract paths, citing limitations in mio. I have a few suggestions to improve the error handling in these new blocks for better consistency and clarity.

#[cfg(any(target_os = "linux", target_os = "android"))]
if path.as_ref().as_os_str().as_bytes().starts_with(b"\0") {
return Err(io::Error::new(
io::ErrorKind::Other,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For consistency and to provide a more descriptive error, it would be better to use io::ErrorKind::InvalidInput here instead of io::ErrorKind::Other. This indicates that the input path type (abstract socket) is not valid for this operation. The new test recv_abstract also expects InvalidInput for a similar case on non-Linux platforms.

Suggested change
io::ErrorKind::Other,
io::ErrorKind::InvalidInput,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Gemini AI reviewer is correct! Since some UDP related methods do not support abstract paths it would be better to return an InvalidInput kind of error to better tell the caller what is the issue.

#[cfg(any(target_os = "linux", target_os = "android"))]
if target.as_ref().as_os_str().as_bytes().starts_with(b"\0") {
return Err(io::Error::new(
io::ErrorKind::Other,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to other functions in this file, it would be better to use io::ErrorKind::InvalidInput here instead of io::ErrorKind::Other to provide a more specific error when an unsupported path type is used.

Suggested change
io::ErrorKind::Other,
io::ErrorKind::InvalidInput,

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Gemini AI reviewer is correct! Since some UDP related methods do not support abstract paths it would be better to return an InvalidInput kind of error to better tell the caller what is the issue.

#[cfg(any(target_os = "linux", target_os = "android"))]
if target.as_ref().as_os_str().as_bytes().starts_with(b"\0") {
return Err(io::Error::new(
io::ErrorKind::Other,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To be consistent with other error handling in this file and provide a more descriptive error, please consider using io::ErrorKind::InvalidInput instead of io::ErrorKind::Other.

Suggested change
io::ErrorKind::Other,
io::ErrorKind::InvalidInput,

Copy link
Copy Markdown
Owner Author

@martin-augment martin-augment Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Gemini AI reviewer is correct! Since some UDP related methods do not support abstract paths it would be better to return an InvalidInput kind of error to better tell the caller what is the issue.

Comment on lines +1285 to +1288
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
"UnixDatagram::send_to(): abstract paths currently unsupported",
)));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There are two small issues here:

  • The error message refers to UnixDatagram::send_to(), but this function is poll_send_to(). The message should be updated to reflect the correct function name.
  • For consistency, it would be better to use io::ErrorKind::InvalidInput instead of io::ErrorKind::Other to indicate that abstract socket paths are not a valid input for this function at this time.
Suggested change
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::Other,
"UnixDatagram::send_to(): abstract paths currently unsupported",
)));
return Poll::Ready(Err(io::Error::new(
io::ErrorKind::InvalidInput,
"UnixDatagram::poll_send_to(): abstract paths currently unsupported",
)));

Copy link
Copy Markdown
Owner Author

@martin-augment martin-augment Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The Gemini AI reviewer is correct! Since some UDP related methods do not support abstract paths it would be better to return an InvalidInput kind of error to better tell the caller what is the issue.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tokio/src/net/unix/datagram/socket.rs`:
- Around line 577-580: The docs incorrectly state "Linux abstract namespace
paths" while the runtime checks also include Android; update the doc comments
that currently read "This method currently does not allow specifying Linux
abstract namespace paths." (and the similar occurrences at the other locations)
to mention Android as well — e.g. "Linux and Android abstract namespace paths"
or "Linux/Android abstract namespace paths"; make this change for all four
methods where the runtime checks use cfg(any(target_os = "linux", target_os =
"android")) (and the additional occurrences you noted) so the documentation
matches the actual cfg-gated behavior.

In `@tokio/tests/uds_datagram.rs`:
- Around line 11-14: The imports currently use
std::os::linux::net::SocketAddrExt for both Linux and Android which breaks on
Android; split the cfg imports so that #[cfg(target_os = "linux")] imports
SocketAddrExt from std::os::linux::net and #[cfg(target_os = "android")] imports
SocketAddrExt from std::os::android::net, while keeping the existing cfg wrapper
for std::os::unix::net as std_net; update the cfg attributes around the
SocketAddrExt and std_net uses (symbols: SocketAddrExt, std_net) so each target
pulls the correct platform module.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a7327b25-6ff5-4ed8-8b85-ba898dbe3ee9

📥 Commits

Reviewing files that changed from the base of the PR and between ad0e3d2 and a593d99.

📒 Files selected for processing (5)
  • tokio/src/net/unix/datagram/socket.rs
  • tokio/src/net/unix/listener.rs
  • tokio/src/net/unix/socketaddr.rs
  • tokio/src/net/unix/stream.rs
  • tokio/tests/uds_datagram.rs

Comment on lines +577 to +580
/// # Limitations
///
/// This method currently does not allow specifying Linux abstract
/// namespace paths.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

The limitation docs should mention Android too.

The runtime checks for abstract paths are gated with cfg(any(target_os = "linux", target_os = "android")) at Lines 618-624, 761-767, 1145-1151, and 1283-1289, so the current "Linux abstract namespace paths" wording is incorrect on Android across all four methods.

Also applies to: 715-718, 1102-1105, 1256-1259

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tokio/src/net/unix/datagram/socket.rs` around lines 577 - 580, The docs
incorrectly state "Linux abstract namespace paths" while the runtime checks also
include Android; update the doc comments that currently read "This method
currently does not allow specifying Linux abstract namespace paths." (and the
similar occurrences at the other locations) to mention Android as well — e.g.
"Linux and Android abstract namespace paths" or "Linux/Android abstract
namespace paths"; make this change for all four methods where the runtime checks
use cfg(any(target_os = "linux", target_os = "android")) (and the additional
occurrences you noted) so the documentation matches the actual cfg-gated
behavior.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The CodeRabbit AI reviewer is correct! The method is available for both Linux and Android (Android is based on Linux but still there are differences), so the documentation should be more explicit that Android is also supported.

Comment on lines +11 to +14
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::linux::net::SocketAddrExt;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::unix::net as std_net;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

On Rust Android targets, is the abstract Unix socket extension trait available as std::os::android::net::SocketAddrExtrather thanstd::os::linux::net::SocketAddrExt?

💡 Result:

Yes. On Android targets the abstract Unix-socket extension trait is exposed as std::os::android::net::SocketAddrExt (and on Linux as std::os::linux::net::SocketAddrExt), as shown by the std source and the rendered docs’ platform-specific import example. [1], [2]

Practical pattern:

#[cfg(target_os = "linux")]
use std::os::linux::net::SocketAddrExt;
#[cfg(target_os = "android")]
use std::os::android::net::SocketAddrExt;

[1] (doc.rust-lang.org) [2] (doc.rust-lang.org)

Citations:


Split the import by platform for Android compatibility.

Lines 11-14 compile for both Linux and Android, but SocketAddrExt is platform-specific. The code attempts to import from std::os::linux::net::SocketAddrExt for both targets, which fails on Android. Android requires std::os::android::net::SocketAddrExt instead. Mirror the split import pattern in tokio/src/net/unix/socketaddr.rs.

🔧 Proposed fix
-#[cfg(any(target_os = "linux", target_os = "android"))]
-use std::os::linux::net::SocketAddrExt;
+#[cfg(target_os = "android")]
+use std::os::android::net::SocketAddrExt;
+#[cfg(target_os = "linux")]
+use std::os::linux::net::SocketAddrExt;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::linux::net::SocketAddrExt;
#[cfg(any(target_os = "linux", target_os = "android"))]
use std::os::unix::net as std_net;
#[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::net as std_net;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tokio/tests/uds_datagram.rs` around lines 11 - 14, The imports currently use
std::os::linux::net::SocketAddrExt for both Linux and Android which breaks on
Android; split the cfg imports so that #[cfg(target_os = "linux")] imports
SocketAddrExt from std::os::linux::net and #[cfg(target_os = "android")] imports
SocketAddrExt from std::os::android::net, while keeping the existing cfg wrapper
for std::os::unix::net as std_net; update the cfg attributes around the
SocketAddrExt and std_net uses (symbols: SocketAddrExt, std_net) so each target
pulls the correct platform module.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

value:good-to-have; category:bug; feedback: The CodeRabbit AI reviewer is correct! The IT test should use one import for Linux and a different one for Android. Since the IT tests are executed only on Linux in the Github Actions CI environment there is no issue at the moment because it is always Linux and the imported file matches the OS. A problem would occur when someone tries to run the test on Android.

@martin-augment
Copy link
Copy Markdown
Owner Author

Bug: Incorrect Android import in test file

In tokio/tests/uds_datagram.rs the test imports std::os::linux::net::SocketAddrExt for both Linux and Android. However std::os::linux does not exist on Android, so this would cause a compile failure on Android targets. The correct pattern (already used in socketaddr.rs lines 3-6 and 73-76) is separate cfg attributes for each OS, importing std::os::android::net::SocketAddrExt on Android and std::os::linux::net::SocketAddrExt on Linux.

value:good-to-have; category:bug; feedback: The Claude AI reviewer is correct! The IT test should use one import for Linux and a different one for Android. Since the IT tests are executed only on Linux in the Github Actions CI environment there is no issue at the moment because it is always Linux and the imported file matches the OS. A problem would occur when someone tries to run the test on Android.

@martin-augment
Copy link
Copy Markdown
Owner Author

Error kind inconsistency

The abstract-path guards added to connect, try_send_to, send_to, and poll_send_to all return io::ErrorKind::Other. io::ErrorKind::InvalidInput is more appropriate since the caller passed an invalid argument. This would also be consistent with what the non-Linux branch of the recv_abstract test already asserts (Some(io::ErrorKind::InvalidInput)).

value:good-to-have; category:bug; feedback: The Claude AI reviewer is correct! Since some UDP related methods do not support abstract paths it would be better to return an InvalidInput kind of error to better tell the caller what is the issue.

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

Successfully merging this pull request may close these issues.

3 participants