Implement inbound UDP handler - #7130
Merged
Merged
Conversation
ThomasRubini
force-pushed
the
udp_handler
branch
from
August 26, 2026 15:08
48e6d49 to
1011f25
Compare
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the CLA Document and I hereby sign the CLA |
ThomasRubini
force-pushed
the
udp_handler
branch
from
August 26, 2026 17:42
ed9a31d to
a6ef39c
Compare
jasnell
reviewed
Aug 26, 2026
jasnell
reviewed
Aug 26, 2026
jasnell
reviewed
Aug 26, 2026
jasnell
reviewed
Aug 26, 2026
jasnell
reviewed
Aug 26, 2026
jasnell
reviewed
Aug 26, 2026
jasnell
reviewed
Aug 26, 2026
dom96
reviewed
Aug 27, 2026
dom96
left a comment
Contributor
There was a problem hiding this comment.
I would ideally like to see this added to the sockets spec before it is implemented: https://sockets-api.proposal.wintertc.org/
It's also worth considering how our design compares to the direct-socket API. Ideally we shouldn't diverge from it unless it's necessary. It would be nice to reuse its UDPMessage + ReadableStream/WritableStream approach for example.
ThomasRubini
force-pushed
the
udp_handler
branch
from
August 27, 2026 18:46
a6ef39c to
f6d23ca
Compare
ThomasRubini
marked this pull request as ready for review
August 27, 2026 20:12
jasnell
reviewed
Sep 3, 2026
harrishancock
left a comment
Collaborator
There was a problem hiding this comment.
I'm still reading, but wanted to leave some initial comments.
ThomasRubini
force-pushed
the
udp_handler
branch
from
September 8, 2026 14:44
0245491 to
bc5033d
Compare
jasnell
reviewed
Sep 14, 2026
jasnell
reviewed
Sep 14, 2026
jasnell
reviewed
Sep 14, 2026
jasnell
approved these changes
Sep 14, 2026
ThomasRubini
force-pushed
the
udp_handler
branch
3 times, most recently
from
September 16, 2026 00:09
9e9da20 to
3ad297f
Compare
it should not have buffering, reflecting JsReadableStream::from()
This avoids an old flow unregistering its key after a new Flow has started using it
Assisted-by: OpenCode:gpt-5.6-sol
Writable datagram chunks remain mutable from JavaScript while an asynchronous send is pending. Snapshotting at the stream boundary prevents later mutation or detachment from changing the packet on the wire. Assisted-by: OpenCode:gpt-5.6-sol
A truncated datagram has permanently lost its tail and cannot be delivered without changing its contents. Dropping it before flow lookup also prevents malformed packets from creating flows or extending their idle lifetime. Assisted-by: OpenCode:gpt-5.6-sol
KJ currently binds only the first resolved address for datagram ports, unlike its stream listener implementation. The socket schema should not promise multi-address behavior that UDP cannot provide. Assisted-by: OpenCode:gpt-5.6-sol
Assisted-by: OpenCode:gpt-5.6-sol
…experimental flag
ThomasRubini
force-pushed
the
udp_handler
branch
from
September 17, 2026 17:18
9fbbf85 to
9817317
Compare
ThomasRubini
force-pushed
the
udp_handler
branch
from
September 17, 2026 19:51
fd34f2f to
842a58c
Compare
Windows handles it in a different way which will be implemented as part of a follow-up PR
Collaborator
|
Internal pipeline is green. Merging |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for workerd to handle inbound UDP "connections" and deliver them to a
connect()handler.It does 2 things:
protocolfield to theSocketobject used in connect() handlers, following [wrangler] addconnectwrangler config section workers-sdk#14995To prevent one "UDP connection"'s slow reader from blocking others, we always read all UDP packets from the kernel, and store them in our own per-connection buffers (in
Flow), dropping new packets for a connection when its buffer is full.The UDP
connect()handler has been implemented as a custom event becauseconnect()onWorkerInterfacerequired akj::AsyncIoStreamwhich is byte-oriented rather than message-oriented like UDP requiresUDP sockets will read and write custom
Datagramobjects instead ofUint8Array, to avoid user confusion if they try to use them with code that expect stream-based sockets.Example usage
testable by adding this bit in a workerd config:
sockets = [ ( name = "http", address = "*:8787", http = (), service = "main" ), ( name = "tcp", address = "*:5432", tcp = (), service = "main" ), ( name = "udp", address = "*:5599", udp = (idleTimeoutMs = 30000, maxPendingBytes = 262144), service = "main" ), ]