Repository navigation
Support hot restart handoff for connectionless UDP flows - #46502
Conversation
Signed-off-by: Filip Cacky <[email protected]>
Signed-off-by: Filip Cacky <[email protected]>
Signed-off-by: Filip Cacky <[email protected]>
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Signed-off-by: Filip Cacky <[email protected]>
adisuissa
left a comment
There was a problem hiding this comment.
/assign-from @envoyproxy/envoy-maintainers
|
@envoyproxy/envoy-maintainers assignee is @nezdolik |
|
/lgtm api |
| } | ||
| flow_it->second = now; | ||
| } else { | ||
| auto [flow_it, inserted] = flow_last_activity_.try_emplace(data.addresses_, now); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
should we also introduce this change behind a feature flag?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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}}];
There was a problem hiding this comment.
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.
Signed-off-by: Filip Cacky <[email protected]>
Signed-off-by: Filip Cacky <[email protected]>
…limit` Signed-off-by: Filip Cacky <[email protected]>
|
|
||
| namespace { | ||
|
|
||
| constexpr uint64_t DefaultUdpFlowLimit = 100000; |
There was a problem hiding this comment.
this default needs to be documented somewhere
|
@filipcacky please fix CI |
Signed-off-by: Filip Cacky <[email protected]>
Thought that was an infra flake. |
| #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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Thanks, moved under ActiveRawUdpListener.
|
/wait |
Signed-off-by: Filip Cacky <[email protected]>
|
@adisuissa could you do api stamp? |
adisuissa
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 {}}]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
I agree that it makes sense to clarify the runtime flag in this description.
|
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).
Reworked it so that a filter opts in to keep its sessions on the same instance during hot restart. Currently only The listener also couldn't track a session correctly on its own. Also added the 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? |
This reverts commit acc3852. Signed-off-by: Filip Cacky <[email protected]>
This reverts commit db36159. Signed-off-by: Filip Cacky <[email protected]>
…dp_flow_limit`" This reverts commit d9f0c42. Signed-off-by: Filip Cacky <[email protected]>
This reverts commit d8b3c67. Signed-off-by: Filip Cacky <[email protected]>
Signed-off-by: Filip Cacky <[email protected]>
Signed-off-by: Filip Cacky <[email protected]>
Signed-off-by: Filip Cacky <[email protected]>
0868ec7 to
2511e87
Compare
Signed-off-by: Filip Cacky <[email protected]>
|
@adisuissa @nezdolik waiting on further review |
|
@filipcacky needs main merge @adisuissa @nezdolik waiting on further review |
|
/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)]() { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
|
i will be out for the rest of the week. |
…ionComplete Signed-off-by: Filip Cacky <[email protected]>
|
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. |
|
/retest |
|
Now "the rest of the week" has expired, so ping @nezdolik :) |
…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]>
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_proxysticky sessions.The RPC forwarding can be disabled by setting
envoy.reloadable_features.udp_hot_restart_session_handoffto 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_handoffFixes #34732