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

proposal: net: ReadMsgUnix without source address #72068

Open
pboyd04 opened this issue Mar 2, 2025 · 3 comments
Open

proposal: net: ReadMsgUnix without source address #72068

pboyd04 opened this issue Mar 2, 2025 · 3 comments
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Milestone

Comments

@pboyd04
Copy link

pboyd04 commented Mar 2, 2025

Proposal Details

Problem
Currently, (*UnixConn) ReadMsgUnix() reads a message from a unix socket, and returns a *UnixAddress even when the calling code doesn't care about the source address. This allocation isn't optimized out by the compiler even when the calling code specifies _ for the return because it is referenced in some intermediate layers.

Proposed Solution
Create (*UnixConn) ReadMsgUnixIgnoreSource() that returns (n, oobn, flags int, err error) and the required underlying functions to support this so that programs that do not care about the source address don't allocate unused data on each call.

Usecase
I'm trying to optimize dbus calls which require multiple calls to ReadMsgUnix per dbus message and I am trying to support this on a limited memory (embedded) system. So any time I can save not allocating and GC'ing is an improvement.

@gopherbot gopherbot added this to the Proposal milestone Mar 2, 2025
@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Mar 2, 2025
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Mar 3, 2025
@ianlancetaylor
Copy link
Member

For your use case, why do you need to use ReadMsgUnix rather than simply calling Read?

@pboyd04
Copy link
Author

pboyd04 commented Mar 3, 2025

For your use case, why do you need to use ReadMsgUnix rather than simply calling Read?

In order to handle Unix file descriptors being sent along with the messages. From the dbus spec:
"The number of Unix file descriptors that accompany the message. If omitted, it is assumed that no Unix file descriptors accompany the message. The actual file descriptors need to be transferred via platform specific mechanism out-of-band. They must be sent at the same time as part of the message itself. They may not be sent before the first byte of the message itself is transferred or after the last byte of the message itself. This header field is controlled by the message sender."

The oob mechanism for the unix socket is only returened with ReadMsgUnix and not with the standard Read since it only passes the regular data and ignores the OOB.

@ianlancetaylor
Copy link
Member

Maybe we should start with a variant of x/sys/unix.Recvmsg that doesn't return a Sockaddr value. That might be enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Projects
Status: Incoming
Development

No branches or pull requests

4 participants