Skip to content

Support hot restart handoff for connectionless UDP flows - #46502

Merged
nezdolik merged 20 commits into
envoyproxy:mainfrom
filipcacky:udp_hotrestart
Sep 9, 2026
Merged

nezdolik merged 20 commits into
envoyproxy:mainfrom
filipcacky:udp_hotrestart

Conversation

@filipcacky

@filipcacky filipcacky commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Commit Message: udp: Support hot restart handoff for connectionless UDP sessions
Additional Description:

The parent instance keeps serving established UDP sessions while draining and forwards packets of unknown sessions to the child over the hot restart RPC, instead of going dark between drain start and parent shutdown. This feature is only supported for udp_proxy sticky sessions.

The RPC forwarding can be disabled by setting envoy.reloadable_features.udp_hot_restart_session_handoff to false, which causes the raw udp listener to keep handling all traffic during hot restart until shutdown.

Risk Level: Medium
Testing: Added unit and integration tests, manual
Docs Changes: Added section about raw UDP hotrestarting to docs/root/intro/arch_overview/listeners/listeners.rst.
Release Notes: Added new_features entry
Platform Specific Features: N/A
Runtime guard: Added envoy.reloadable_features.udp_hot_restart_session_handoff
Fixes #34732

@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @markdroth
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #46502 was opened by filipcacky.

see: more, trace.

@adisuissa adisuissa 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.

/assign-from @envoyproxy/envoy-maintainers

@repokitteh-read-only

Copy link
Copy Markdown

@envoyproxy/envoy-maintainers assignee is @nezdolik

🐱

Caused by: a #46502 (review) was submitted by @adisuissa.

see: more, trace.

@markdroth

Copy link
Copy Markdown
Contributor

/lgtm api

@repokitteh-read-only repokitteh-read-only Bot removed the api label Aug 4, 2026
Comment thread source/server/active_udp_listener.cc Outdated
}
flow_it->second = now;
} else {
auto [flow_it, inserted] = flow_last_activity_.try_emplace(data.addresses_, now);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks like this adds an unbounded flow map to every connectionless UDP listener. Each new address tuple is stored before filter processing, including packets that are later dropped. (traffic with many unique tuples can increase memory usage) Please add a capacity limit or eviction strategy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we also introduce this change behind a feature flag?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added envoy.resource_limits.listener.<name>.udp_flow_limit, flows over this limit go to the new instance during hotrestart. Evicting oldest during tracking would be O(N) in hotpath (onDataWorker), vs O(1) in hotpath and O(N) in timer.

I don't think the feature flag is necessary, but up to you. Currently udp listeners don't work at all during hotrestart, can't get much worse than that. The NonDispatchedUdpPacketHandler is in use for QUIC already and this is mostly just wiring it up with 4tuple tracking.

// Should not be set lower than the idle timeout of the proxying filter (e.g. the udp_proxy
// :ref:`idle_timeout <envoy_v3_api_field_extensions.filters.udp.udp_proxy.v3.UdpProxyConfig.idle_timeout>`),
// otherwise live sessions may be handed to the child instance mid-drain. Defaults to 1 minute.
google.protobuf.Duration flow_idle_timeout = 9;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

since duration can be negative (https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/duration.proto#L106) or zero, please add proto validation here, e.g.:

google.protobuf.Duration flow_idle_timeout = 9
    [(validate.rules).duration = {gte {nanos: 1000000}}];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Other idle_timeout fields don't specify proto validations, PROTOBUF_GET_MS_OR_DEFAULT throws on negative.

Did gt {} since anything else would be arbitrary.


namespace {

constexpr uint64_t DefaultUdpFlowLimit = 100000;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this default needs to be documented somewhere

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@nezdolik

Copy link
Copy Markdown
Member

@filipcacky please fix CI

@filipcacky

Copy link
Copy Markdown
Contributor Author

@filipcacky please fix CI

Thought that was an infra flake. Uploading BEP referenced local file: UNAUTHENTICATED: null... Error while uploading artifact...

Comment thread source/server/active_udp_listener.h Outdated
#define ALL_UDP_LISTENER_STATS(COUNTER) COUNTER(downstream_rx_datagram_dropped)
#define ALL_UDP_LISTENER_STATS(COUNTER, GAUGE) \
COUNTER(downstream_rx_datagram_dropped) \
GAUGE(downstream_flows_active, Accumulate)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this will make ActiveQuicListener also publish that stat even though it will not be used by the listener. Should prob be moved to ActiveRawUdpListener specific stats

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, moved under ActiveRawUdpListener.

@nezdolik

Copy link
Copy Markdown
Member

/wait

nezdolik
nezdolik previously approved these changes Aug 13, 2026
@nezdolik

Copy link
Copy Markdown
Member

@adisuissa could you do api stamp?

@adisuissa adisuissa 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.

Thanks, left some API comments.

// [#extension-category: envoy.udp_packet_writer]
core.v3.TypedExtensionConfig udp_packet_packet_writer_config = 8;

// Idle timeout for the per-flow tracking used during hot restart handoff. Only applies

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.

I wasn't aware of the term UDP-flow, and had to look it up in multiple places. Please add a reference to its definition.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Finding a citable definition for this is hard. It's used in RFC 8085 and conntrack.

Thought about using udp_proxy "session" naming for consistency, but that manages more state than a timestamp (filter chain...). dns_filter needs no state at all.

I'll define it inline unless you'd prefer the "session" naming.

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.

IMHO it is better to have a more precise definition (flow) rather than using the wrong one (session).
My understanding in this domain is very limited, and I would suggest to briefly define what a flow is in this context, and have the reference to the RFC so (hopefully) one can learn more about that later.

// Should not be set lower than the idle timeout of the proxying filter (e.g. the udp_proxy
// :ref:`idle_timeout <envoy_v3_api_field_extensions.filters.udp.udp_proxy.v3.UdpProxyConfig.idle_timeout>`),
// otherwise live sessions may be handed to the child instance mid-drain. Defaults to 1 minute.
google.protobuf.Duration flow_idle_timeout = 9 [(validate.rules).duration = {gt {}}];

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.

IIUC this timeout is specifically for flows after a hot_restart occurs.
I wonder if it would be better to name this explicitly hot_restart_flow_idle_timeout (or something similar), just in case a new feature will be needed to support flow idle-timeout not for the hot-restart case. WDYT?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Also makes it immediately obvious when the timeout affects anything, agreed. I'll also link envoy.resource_limits.listener.<name>.udp_flow_limit here, since that can be set to zero to disable the feature.

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.

I agree that it makes sense to clarify the runtime flag in this description.

@filipcacky
filipcacky requested a review from danzh2010 as a code owner August 16, 2026 14:37
@repokitteh-read-only

Copy link
Copy Markdown

CC @envoyproxy/runtime-guard-changes: FYI only for changes made to (source/common/runtime/runtime_features.cc).

🐱

Caused by: #46502 was synchronize by filipcacky.

see: more, trace.

@filipcacky

Copy link
Copy Markdown
Contributor Author

I spent more time on this feature while thinking about the naming and came to the conclusion it was wrong to dictate to the filters what a "flow" or "session" is, and their lifetime. I also wasn't happy with the ergonomics (config for different raw UDP listener deployments).

dns_filter and udp_proxy with use_per_packet_load_balancing == true have no concept of, or need for, a session. For these two it would've made most sense to (explicitly, oof) disable the tracking by setting the limit to 0.

Reworked it so that a filter opts in to keep its sessions on the same instance during hot restart. Currently only udp_proxy with sticky sessions does this, where it makes most sense. The number of tracked sessions is bounded by udp_proxy, which does this in ActiveSession::setClusterInfo() with the cluster resource manager.

The listener also couldn't track a session correctly on its own. udp_proxy keeps a session alive on upstream traffic too, which the listener couldn't see, so the idle timer would drop sessions the filter still considered live.

Also added the envoy.reloadable_features.udp_hot_restart_session_handoff runtime guard in case the RPC overhead ends up being too high and it needs eBPF. When off, the old instance keeps serving all traffic until it exits.

As a bonus this resolves the "flow" vs "session" naming issue, which genuinely caught me off guard. I thought it was ubiquitous, but it's mostly networking and firewall vocabulary. Envoy already uses "session" in the listener docs and elsewhere.

Could you please give this another pass @nezdolik @adisuissa?

@phlax

phlax commented Aug 19, 2026

Copy link
Copy Markdown
Member

@adisuissa @nezdolik waiting on further review

@mathetake

Copy link
Copy Markdown
Member

@filipcacky needs main merge

@adisuissa @nezdolik waiting on further review

@filipcacky

Copy link
Copy Markdown
Contributor Author

/retest

Network::UdpRecvData::LocalPeerAddresses key{local_address, peer_address};
const bool inserted = active_sessions_.insert(key).second;
ASSERT(inserted, "hot restart session registered twice");
return std::make_unique<UdpHotRestartSessionHandleImpl>([this, key = std::move(key)]() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since you capture listener here by raw pointer, it could be the case that this callback outlives the listener (this). And then accessing active_sessions_ could crash (since listener is already destroyed). Could we unregister it in ActiveSession::onSessionComplete() or otherwise make this cleanup safe (e.g. by capturing by weak pointer)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh, i suppose that could happen if the TunnelingActiveSession::onBelowWriteBufferLowWatermark callback keeps the session alive in dispatcher. Explicit clear it is since ActiveRawUdpListener is unique_ptr. Thank you

@nezdolik

Copy link
Copy Markdown
Member

i will be out for the rest of the week.

@ravenblackx

Copy link
Copy Markdown
Contributor

Awaiting nezdolik, no ping since week expectation was announced, but saying just to get this out of "hasn't been touched for days" state so the on-call autonag will shush.

@filipcacky

Copy link
Copy Markdown
Contributor Author

/retest

@ravenblackx

Copy link
Copy Markdown
Contributor

Now "the rest of the week" has expired, so ping @nezdolik :)

@ravenblackx
ravenblackx requested a review from nezdolik September 4, 2026 15:39
@nezdolik
nezdolik merged commit 712586a into envoyproxy:main Sep 9, 2026
28 checks passed
mattklein123 pushed a commit that referenced this pull request Sep 30, 2026
…space (#47743)

### Commit Message
hot restart: forward UDP packets by listener address and network
namespace

### Additional Description
Since #46502 the draining parent forwards datagrams of unknown sessions
to the child. Two parts of
that path ignored the listener's network namespace:
`UdpForwardingContext::registerListener` keyed
the child's registry on `address->asString()`, which omits the
namespace, so listeners bound to the
same `ip:port` via different `network_namespace_filepath` values
collapsed to one entry (the
duplicate assert is debug-only); and the parent forwarded the datagram's
destination
(`urlFromDatagramAddress(packet.addresses_.local_)`), which on a
`transparent` socket is the
original destination rather than the bind address, so the lookup fell
through to the any-address
entry. Every forwarded datagram from any such listener was delivered to
the first registered
listener's `udp_proxy`, replying from a socket in the wrong namespace.

The `NonDispatchedUdpPacketHandler` interface now receives the
forwarding listener's bind address
(both the raw UDP and the QUIC listener pass their listen socket's local
address), the parent adds
`listener_addr` and `network_namespace` to `ForwardedUdpPacket`, and the
child keys its registry on
namespace plus address and resolves forwarded packets by listener
address. A message without the
new fields, from a parent that predates them, is resolved exactly as
before, so mixed-version hot
restarts keep working in both directions. Socket inheritance was already
namespace-aware and is
unchanged.

### Risk Level
Low. Only affects hot restart UDP forwarding; no behavior change for
listeners without a network
namespace or with distinct addresses.

### Testing
- `hot_restarting_child_test`: forwarding by listener address to the
right one of two listeners
sharing an address across namespaces with a transparent destination;
destination-based fallback
for messages without the new fields; no cross-namespace or
namespace-less match of a namespaced
  listener.
- `hot_restarting_parent_test`: the forwarded message carries the
listener address and namespace.
- Updated `active_udp_listener_test`, `active_quic_listener_test` and
`connection_handler_test`
  for the handler signature.

### Docs Changes
One sentence in the listeners overview.

### Release Notes
Added a bug fix fragment.

### Platform Specific Features
N/A

Fixes #47742

Signed-off-by: Bruno Palermo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UDP should be supported during hot restart

7 participants