Skip to content

net: WriteMsgUDPAddrPort should accept zero value destination addresses [1.25 backport] #75003

@gopherbot

Description

@gopherbot

@database64128 requested issue #74841 to be considered for backport to the next 1.25 minor release.

@gopherbot please open backport issues. Now this is a tough one compared to #74737.

In user code, the same code path usually needs to handle both connected and unconnected sockets. There's no workaround other than checking and not using WriteMsgUDPAddrPort when the address is zero value. This is quite ugly.

n, cmsgn, err := c.WriteMsgUDPAddrPort(b, cmsg, ap)
if err != nil {}

becomes:

var (
	n     int
	cmsgn int
	err   error
)
// Long explanation here...
if ap.IsValid() {
	n, cmsgn, err = c.WriteMsgUDPAddrPort(b, cmsg, ap)
} else {
	n, cmsgn, err = c.WriteMsgUDP(b, cmsg, nil)
}
if err != nil {}

The fix involves 3 separate CLs, touching internal/poll and syscall. Changes in these packages are mostly adding nil checks though, so risks should be low.

Metadata

Metadata

Assignees

No one assigned

    Labels

    CherryPickCandidateUsed during the release process for point releases

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions