Skip to content

Surface UDP peer address and declare UDP listeners to workers - #7503

Open
guybedford wants to merge 2 commits into
mainfrom
gbedford/udp-remote-address
Open

guybedford wants to merge 2 commits into
mainfrom
gbedford/udp-remote-address

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

This fills in two gaps in the inbound UDP connect() handler from #7130 that are prerequisites for routing UDP flows through a node:dgram layer the way node:net consumes TCP listeners.

  • socket.opened.remoteAddress now reports the peer address:port. The listener's Flow already knew the peer but it was dropped before setupDatagramSocket(); it is now threaded through UdpConnectCustomEvent and the udpConnect RPC params, and clientAddress is set on the request metadata as the TCP listener does.
  • socket.opened.localAddress is the bound host:port authority rather than the raw config string (e.g. *:0), matching TCP.
  • UDP sockets are registered in inboundListeners with protocol "udp", so getInboundListeners() declares them alongside TCP ones.

Tests: udp-connect gains a remote/local address round-trip; net-server-nodejs-test adds a UDP listener to its config to check it does not land in the TCP port table.

The UDP connect() handler received no remoteAddress: the listener's Flow
knew the peer but it was dropped before reaching setupDatagramSocket().
Thread it through UdpConnectCustomEvent (and the udpConnect RPC params)
so socket.opened.remoteAddress reports the peer, and set clientAddress
on the request metadata as the TCP listener does.

The local address handed to the handler was the raw config string
(e.g. "*:0") rather than the bound endpoint; use the same
host:boundPort authority the TCP listener uses.

UDP sockets are now registered in inboundListeners with protocol
"udp", so getInboundListeners() declares them alongside TCP ones.
@guybedford
guybedford requested review from a team as code owners September 24, 2026 18:24
@ask-bonk

ask-bonk Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

Comment thread src/workerd/io/worker-interface.capnp Outdated
Comment thread src/workerd/server/server.c++
The peer address reaches the UDP connect event the way it reaches TCP
connect(): via SubrequestMetadata.clientAddress into WorkerEntrypoint,
which now stores it on IoContext_IncomingRequest for custom events to
read, rather than as a udpConnect RPC parameter. For workerd-to-workerd
RPC, startEvent() carries the client address alongside the cf blob.
@ThomasRubini

Copy link
Copy Markdown
Contributor

I don't have the permission to formally approve anymore, but everything looks good to me!

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.

2 participants