Skip to content

netutil: preserve UDP peer address after packet release - #36

Merged
Rememorio merged 1 commit into
trpc-group:mainfrom
print-happy:bugfix/preserve-udp-peer-address
Aug 19, 2026
Merged

Rememorio merged 1 commit into
trpc-group:mainfrom
print-happy:bugfix/preserve-udp-peer-address

Conversation

@print-happy

Copy link
Copy Markdown
Contributor

Background

SockaddrSliceToUDPAddr currently returns a net.IP slice that aliases the raw sockaddr memory in the UDP receive buffer.

After Packet.Free() or ReadFrom returns, that buffer may be reused by a later receive operation. The peer IP retained by the caller can then be overwritten while the port remains unchanged, causing responses to be lost or sent to the wrong peer.

Changes

  • Copy IPv4 and IPv6 address bytes into storage owned by the returned net.UDPAddr.
  • Add regression tests that overwrite the original sockaddr buffer and verify that the decoded address remains unchanged.

Compatibility

  • No exported API changes.
  • Each conversion adds owned backing storage for 4 bytes on IPv4 or 16 bytes on IPv6.
  • Port and IPv6 zone handling remain unchanged.

Validation

  • go test -race -count=10 ./internal/netutil
  • go test ./...
  • go vet ./...

Copy the IPv4 and IPv6 address bytes before returning a UDP peer address so receive-buffer reuse cannot mutate it. Add regression coverage for both address families.
@github-actions

github-actions Bot commented Aug 19, 2026 •

Copy link
Copy Markdown

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@print-happy

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@print-happy

Copy link
Copy Markdown
Contributor Author

recheck

1 similar comment
@print-happy

Copy link
Copy Markdown
Contributor Author

recheck

@Rememorio Rememorio left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@Rememorio
Rememorio merged commit b10c1ae into trpc-group:main Aug 19, 2026
6 of 7 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants