You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HTTP/3 hot restart should be supported with eBPF #34731
In #19454, software-level support was added for HTTP/3 during hot restart, in which packets are forwarded from parent instance to child instance for the duration of the hot restart handoff.
Ideally this soft support could be bypassed using eBPF filters to deliver packets to the right instance first time.
To achieve this it would be necessary to:
have the QUIC eBPF rule direct packets to the newer instance if they don't have an instance ID in the QUIC header.
have the QUIC eBPF rule direct packets to the specified instance if they do have an instance ID.
modify the hot restart behavior that causes the new instance to not listen until the parent is shut down, to listen immediately if there is eBPF support available. (Probably in pause())
Build on the existing QUIC-LB connection ID generator pattern, which already encodes worker ID in the last byte. I'm thinking of:
Using the hot restart epoch as the instance ID
Encoding it alongside the worker ID (2 bytes total: 1 for instance, 1 for worker)
Ensuring backwards compatibility by treating missing instance ID as "route to newest instance"
2. eBPF Modifications
Extend the existing route.bpf logic:
For packets with instance ID: route to the socket matching that instance
For packets without instance ID (new connections or old-format CIDs): route to the newest instance
The instance->socket mapping could use the socket order in the SO_REUSEPORT group, with newer instances appending to the group
3. UDP Listener Changes
Modify UdpListenerImpl to skip the paused state when eBPF instance routing is available:
// In UdpListenerImpl constructorif (paused() && !hasEbpfInstanceRouting()) {
parent_drained_callback_registrar_->registerParentDrainedCallback(...);
}
4. Configuration
Add a configuration option to enable this feature, defaulting to off for backwards compatibility.
Open Questions
Socket ordering: Is relying on SO_REUSEPORT socket group ordering for instance->socket mapping reliable, or should we use BPF maps for explicit mapping?
Instance ID size: Is 1 byte (256 instances) sufficient, or should we plan for more?
Scope: Should this be implemented as an extension to the existing QUIC-LB generator, or as a separate generator?
Rollout: Any concerns about rolling upgrades where old instances don't have instance IDs in their CIDs?
Happy to discuss further or adjust the approach based on your feedback.
For question (2), 1 byte is plenty since it's highly unusual to have even "two layers of hot restart" happening (i.e. even 1 bit could arguably be enough). I think the existing behavior is already likely to be unreliable with hot restarting while already hot restarting.
For question (4) (and statement (2)), how do you distinguish "packets with instance id" from "packets without instance id" when they're not new connections? If there's a version indicator in the CID, I would suggest that "packets without instance id" (or that have a mismatched version) that are not new connections and are being routed by a version of eBPF that would be setting an instance id, should be routed to the oldest active instance, not to latest instance, since it's implied by the absence of instance id that they don't belong to the latest instance.
I have no strong feelings about question 3, and I think BPF maps for question 1, but I'd defer either of those to @danzh2010 .
Re 1), I'm not sure if the SO_REUSEPORT socket group ordering is reliable or not in this case, so might just use BPF maps.
Re 3), it depends on hot restart users which CID generator they want to use, whether they want QUIC LB or not.
Currently the deterministic generator preserves the first 4 bytes for routing and uses the last byte for worker ID. I'm proposing to use the second-to-last byte for instance ID:
This maintains backwards compatibility with existing eBPF worker routing (last byte) while adding instance routing.
Version Detection
Per @ravenblackx's point about distinguishing old vs new CID formats: I'm considering using a magic byte or bit pattern in the preserved first 4 bytes to indicate the format version. Alternatively, we could use CID length as an indicator (new format = length + 1).
Which approach do you prefer?
Magic byte/pattern in first 4 bytes
CID length difference
Other?
Implementation Scope
Given @danzh2010's comment that the generator choice depends on user needs, I'm planning to:
Extend the existing deterministic generator with an optional encode_instance_id config flag
Keep it disabled by default for backwards compatibility
Add corresponding eBPF logic that checks for instance ID presence
Does this approach work, or would you prefer a separate generator extension?
BPF Maps
I'll use BPF maps for instance->socket mapping as suggested. The map would be:
Key: instance ID (uint8)
Value: socket index in the reuseport group
The map would be populated when each instance starts listening.
The proposal looks good to me, and a skim over the code looks like it's on a decent track.
I think the "known issue" is fine - some packet loss is expected anyway for http3 so a small amount of misdirection should be recoverable.
One question about this:
If a parent process crashes during hot restart before all connections are closed (DCIDs retired), The child process needs to clean up the socket_map or cid_map, This should be doable by iterating over the maps and removing stale entries via a socket cookie.
What happens if a parent process crashes before hot restart even begins?
(And which way are you leaning, option 1 or option 2?)
The program and maps stay alive as long as at least one socket they're attached to remains open (or pinned maps/progs which also hold refcnt).
If we pin the program to bpffs and a process crashes, we need to clean up the map after loading or delete the pin before launching new process with the same pin path.
If its not pinned, the program and maps get cleaned up after the sockets are closed, the kernel handles that for us during a crash.
If it crashes after we've opened sockets in the same reuseport group, we hold the refcount to the program/maps and are responsible for cleanup ourselves.
Implemented pinning, SCM_RIGHTS and both options to get a better idea for the proppsal.
Leaning towards SCM_RIGHTS since it makes cleanup easier. Having the program pinned makes debugging less involved, you can just point bpftool at the pin path. It can stay as opt-in just for debugging, I think we'd have to add cleanup logic to the python hot restart script for production.
Option 1 seems awkward, requires the sentinel bit if we don't want to have a chance at dropping cons during hotrestart... Didn't think too much about all of the implications. With option 2 we can just use the CIDs as they are, adding another UDP listener alongside the QUIC listener seems fine, and writing it was straightforward.
There is still a question whether we want to pull in libbpf and libelf as dependencies. It makes loading the program and working with the maps easier, although its doable without - see quic_lb filter_ = {..., concurrency, ...};.
Would strongly recommend not relying on the python hot restart script doing cleanup, because different environments require different wrappers - the python hot restart script is more of a template than a solution. I think there's also a risky race, where it's possible for the wrapper to start up the new instance then some management process kills the old envoy instance before the new instance has transferred information. Specifically leading to this path. (Even if cleanup is added in that path there's still a small race danger where the parent gets killed after the connection is established but before the data is synchronized, but that window is much smaller. Hitting that extra-risk path already causes a deadlocked startup.)
It sounds like with SCM_RIGHTS maybe the cleanup of any previous instance could just be done as part of the initialization of the new instance, which would avoid all special casing of cleanup (the only "special case" being "there is something existing").
Re pulling in dependencies, I don't have enough information to make a recommendation - as a general thing I would say don't pull in a library unless it saves at least 50 lines of code per library, since the boilerplate for pulling in each library is close to that size in bzl files, and it also creates a maintenance burden [keeping version up to date] and a review blind spot [risk of upstream malicious changes that we don't review closely] and requires external license and security posture checks.
Yep, sounds good to me (would still like some opinions from @danzh2010 but I haven't heard a peep from them in a while so maybe we're on our own).
Not sure if cleanup could be totally divested to the child instance in a way that might be simpler - for any "no hot restart" case the cleanup would happen automatically anyway on exit, and when there is a hot restart connection, an "everything old" cleanup could be triggered from multiple places - in the "failed to connect to the old instance" branch that implies the parent got killed at an inconvenient time, or in the "parent shutdown is complete" branch. But maybe that would be problematically worse, if the entries aren't getting cleaned up immediately as each connection closes, or if they are and double-cleanup on one connection would be a problem.
Coming back to this thread. Thanks @filipcacky for the proposal and the prototype, that's a great starting point. Before we start cutting PRs I'd love to close out the few questions still floating around so we're all on the same page.
Option 1 vs Option 2 from the proposal. Sounds like @filipcacky is leaning Option 2 (SCM_RIGHTS, a separate UDP listener next to the QUIC one, CIDs used as is). Does that work for everyone, or are there concerns worth airing first?
Crash cleanup. Current thinking is SCM_RIGHTS with the new instance handling cleanup on init, though @ravenblackx also floated pushing all cleanup down to the child. Any preference between those two?
libbpf and libelf. Worth pulling in, or are we better off staying with the hand rolled approach the QUIC LB filter uses today? Curious if the savings actually clear @ravenblackx's rough 50 line per library bar.
@danzh2010, would really value your take here, especially on 1 and 2. No rush at all, just don't want to move forward without you since you had good input earlier on BPF maps and the generator side.
Happy to pitch in on implementation or reviews once we've aligned. Thanks all!
Coming back to this thread. Thanks @filipcacky for the proposal and the prototype, that's a great starting point. Before we start cutting PRs I'd love to close out the few questions still floating around so we're all on the same page.
Option 1 vs Option 2 from the proposal. Sounds like @filipcacky is leaning Option 2 (SCM_RIGHTS, a separate UDP listener next to the QUIC one, CIDs used as is). Does that work for everyone, or are there concerns worth airing first?
TBH, I don't see a clear reason why Option2 is better than Option1, given the additional listener and eBPF map look up and fallback. CID update in QUIC has race by nature. So to keep tracking all CIDs in use you need to keep some retired CIDs around for sometime. This is overly complicated to me for an eBPF program.
Can you do a comparison between these 2 options?
Crash cleanup. Current thinking is SCM_RIGHTS with the new instance handling cleanup on init, though @ravenblackx also floated pushing all cleanup down to the child. Any preference between those two?
I don't care about the way of cleaning up the old instance as google doesn't use hot restart. So up-to your choice.
libbpf and libelf. Worth pulling in, or are we better off staying with the hand rolled approach the QUIC LB filter uses today? Curious if the savings actually clear @ravenblackx's rough 50 line per library bar.
@danzh2010, would really value your take here, especially on 1 and 2. No rush at all, just don't want to move forward without you since you had good input earlier on BPF maps and the generator side.> > Happy to pitch in on implementation or reviews once we've aligned. Thanks all!
TBH, I don't see a clear reason why Option2 is better than Option1, given the additional listener and eBPF map lookup and fallback.
Both options have two lookups.
The eBPF equivalent of cBPF's return key % concurrency, which indexes the SO_REUSEPORT group,
is AFAIK only bpf_sk_select_reuseport on a REUSEPORT_SOCKARRAY, SOCKMAP, or SOCKHASH.
IMO we still need one lookup for established connections and a fallback for new ones.
I went over the BPF map limitations again and found I made an error. SOCKMAP/SOCKHASH coexist fine, but pairing a REUSEPORT_SOCKARRAY with any other map fails.
I assumed this limitation applied to all BPF map types and didn't doublecheck.
Option1 and Option2 with separate sockets were designed to work around these limitations.
My main concern with Option1 was collisions on worker IDs. It's unlikely, but I wanted correctness regardless
(didn't like that a CID equal to a worker_id could get dropped during hot-restart).
Not needing two sockets per listener simplifies things,
we can use SOCKHASH for CID -> socket and a SOCKMAP fallback for worker_id -> socket. SOCKHASH holds state to support multiple epochs,
while SOCKMAP is functionally equivalent to cBPF's return key % concurrency for routing new connections to active sockets.
I think we could skip the SOCKHASH when hotrestart isn't running and route packets only based on the SOCKMAP,
if there are any concerns about overhead of the hash lookup, would need to benchmark first.
Apologies for the confusion, I've dropped the additional listener, updated the proposal and the proof-of-concept code, and tested that it works.
CID update in QUIC has race by nature. So to keep tracking all CIDs in use you need to keep some retired CIDs around for some time. This is overly complicated to me for an eBPF program.
QuicDispatcher::MaybeDispatchPacket dispatches packets based on reference_counted_session_map_.
As I understand it, after QuicDispatcher::OnConnectionIdRetired is called,
packets with a retired CID go through QuicDispatcher::ProcessPacket, MaybeDispatchPacket returns false,
and they're dropped in ProcessHeader via ValidityChecks.
I don't see why we'd need to keep the DCID around longer than that, can you please elaborate?
TBH, I don't see a clear reason why Option2 is better than Option1, given the additional listener and eBPF map lookup and fallback.
Both options have two lookups. The eBPF equivalent of cBPF's return key % concurrency, which indexes the SO_REUSEPORT group, is AFAIK only bpf_sk_select_reuseport on a REUSEPORT_SOCKARRAY, SOCKMAP, or SOCKHASH. IMO we still need one lookup for established connections and a fallback for new ones.
Just thinking aloud, can we encode all the states in CID, so that you don't need to deliberately maintain the CID to FD mapping? If the CID is encoded with Envoy instance ID, and the eBPF program maintain its own stable FD array along aside of REUSEPORT_SOCKARRAY, you can still use key % concurrency as the index to your own FD array for both existing and new connections. If the index->FD mapping is stable, the same algorithm can be used to dispatch both existing and new connections.
I went over the BPF map limitations again and found I made an error. SOCKMAP/SOCKHASH coexist fine, but pairing a REUSEPORT_SOCKARRAY with any other map fails.
This sounds more reasonable. Thanks for doing the researching.
Option1 and Option2 with separate sockets were designed to work around these limitations. My main concern with Option1 was collisions on worker IDs. It's unlikely, but I wanted correctness regardless (didn't like that a CID equal to a worker_id could get dropped during hot-restart).
Not needing two sockets per listener simplifies things, we can use SOCKHASH for CID -> socket and a SOCKMAP fallback for worker_id -> socket. SOCKHASH holds state to support multiple epochs, while SOCKMAP is functionally equivalent to cBPF's return key % concurrency for routing new connections to active sockets.
I think we could skip the SOCKHASH when hotrestart isn't running and route packets only based on the SOCKMAP, if there are any concerns about overhead of the hash lookup, would need to benchmark first.
QuicDispatcher::MaybeDispatchPacket dispatches packets based on reference_counted_session_map_. As I understand it, after QuicDispatcher::OnConnectionIdRetired is called, packets with a retired CID go through QuicDispatcher::ProcessPacket, MaybeDispatchPacket returns false, and they're dropped in ProcessHeader via ValidityChecks.
If we only need to maintain the per CID -> FD map during hot restart, that'll be great. But I still think it's even better if we don't have to maintain this map.
And you can keep track of CID lifetime using these QUICHE interfaces to sync up with the internal reference_counted_session_map_. But IMO it's overkill. And I don't know if updating the SOCKHASH for every CID updates is scalable or not.
The JIT-ed program grew from 370 to 409 bytes, but that should more than pay for itself by removing the hash-map lookups and inserts, nice! Would be interesting to properly benchmark.
Re the cleanup question, to be clear I was floating the alternative cleanup option only as "maybe it would be easier/simpler" - I have no preference between the two ways, other than whichever is easier/simpler. i.e. I wasn't saying "please do it this way," I was saying only "you might find it's easier this way."
The main reason I think it might be easier being, cleanup in one thread [the one that if it doesn't survive means the whole process is terminated] is less likely to result in inconsistent state than split cleanup that could be half-interrupted by a poorly timed SIGKILL or similar hitting the parent instance.
But if it's fully cleaned up before the interprocess communication completes then worst case wouldn't be any worse than the current worst case, where a parent-kill during that communication window already results in a deadlocked child instance - so a split cleanup with the property "complete before communication completes" would also be fine.
If we use REUSEPORT_SOCKARRAY, then we don't need to worry about cleanup at all, the kernel removes the socket from the map once the socket is closed (this is where the limitation comes from).
Worked on it a bit more and got LDS updates working aswell. Pre-allocate num_maps REUSEPORT_SOCKARRAYs inside an ARRAY_OF_MAPS, each sized up to max allowed concurrency. During an LDS update/hotrestart a listener grabs the next available map index.
Routing long headers based on DCID[0..4] % concurrency and the current in-use map. For short headers, i just tagged the CID with map index and worker id. I don't like the worker id in CID though, would be probably better to store concurrency for each map in-program, so we can just do DCID[0..4] % concurrency instead of exposing the worker in CID.
Are you going to make this work for any connection ID generator, or only for the deterministic ID generator? If you're going to support the QUIC-LB generator, using the first 8 bytes of the CID for anything could lead to poor results in some configurations (in unencrypted mode, I believe the first 8 bytes could be the same for every CID). If you use the full 20-byte maximum CID, it'll work as expected. I'm not sure if doing something with the first 8 bytes is still part of the proposal or not.
What happens if (in a future version of Envoy) we need to change how QUIC packets are routed during a hot-restart? Eg, we're adding some new functionality, and need to encode the CID differently, or something similar?
Will the new encoding be always enabled, or configurable? If it's configurable but disabled and a hot-restart is performed, what happens?
Are you going to make this work for any connection ID generator, or only for the deterministic ID generator?
Planning a new CID generator based on deterministic, since the proposal needs another field on top of worker_id. I'm not too familiar with the QUIC-LB RFC, so I'd like to land this as a separate extension first, would be happy to help with quic_lb after if that's wanted.
What happens if (in a future version of Envoy) we need to change how QUIC packets are routed during a hot-restart?
The CID format can't change once the extension is running. We could tag CIDs with a version and branch to different handlers in the eBPF program (tail call on the version field) to let routing change across restarts, but that seems out of scope for now.
Will the new encoding be always enabled, or configurable? If it's configurable but disabled and a hot-restart is performed, what happens?
The plan is another extension, so it's always on within that extension. I hadn't considered swapping generators across a hot restart (deterministic → new, or none → new). Pre-existing connections carry CIDs without the routing fields, so they'd break. Seems complicated, probably best disallowed during hot restart/listener config swap.
This makes sense to me as a new extension. Hot-restart is probably mutually exclusive with quic-lb, so that support isn't worth adding extra effort for.
Ah, maybe not quite the same - but our setup does involve using some part of the connection id as a marker for which host to route to, which sounds pretty similar, so may be related enough to bear in mind at least. (But if it's just "I'll have to modify our connection id generator to accommodate the same thing" then that's expected and fine.)
Right; I'm not saying we could/should never use these two things together, but that from my initial view they'd be less common to use together, so it's fine to wait for a need before trying to address it.
Activity
ravenblackx commentedon Jun 13, 2024
@danzh2010 for awareness (it's possible I might work on this but unlikely, and definitely not soon)
willianpaixao commentedon Dec 4, 2025
Hi @ravenblackx @danzh2010,
I'm interested in working on this feature.
Proposed Approach
1. Instance ID Encoding
Build on the existing QUIC-LB connection ID generator pattern, which already encodes worker ID in the last byte. I'm thinking of:
2. eBPF Modifications
Extend the existing
route.bpflogic:SO_REUSEPORTgroup, with newer instances appending to the group3. UDP Listener Changes
Modify
UdpListenerImplto skip the paused state when eBPF instance routing is available:4. Configuration
Add a configuration option to enable this feature, defaulting to off for backwards compatibility.
Open Questions
SO_REUSEPORTsocket group ordering for instance->socket mapping reliable, or should we use BPF maps for explicit mapping?Happy to discuss further or adjust the approach based on your feedback.
ravenblackx commentedon Dec 4, 2025
For question (2), 1 byte is plenty since it's highly unusual to have even "two layers of hot restart" happening (i.e. even 1 bit could arguably be enough). I think the existing behavior is already likely to be unreliable with hot restarting while already hot restarting.
For question (4) (and statement (2)), how do you distinguish "packets with instance id" from "packets without instance id" when they're not new connections? If there's a version indicator in the CID, I would suggest that "packets without instance id" (or that have a mismatched version) that are not new connections and are being routed by a version of eBPF that would be setting an instance id, should be routed to the oldest active instance, not to latest instance, since it's implied by the absence of instance id that they don't belong to the latest instance.
I have no strong feelings about question 3, and I think BPF maps for question 1, but I'd defer either of those to @danzh2010 .
danzh2010 commentedon Jan 2, 2026
Re 1), I'm not sure if the SO_REUSEPORT socket group ordering is reliable or not in this case, so might just use BPF maps.
Re 3), it depends on hot restart users which CID generator they want to use, whether they want QUIC LB or not.
willianpaixao commentedon Jan 2, 2026
Thanks for the feedback @ravenblackx @danzh2010! Happy new year!
A few follow-up points:
CID Format Proposal
Currently the deterministic generator preserves the first 4 bytes for routing and uses the last byte for worker ID. I'm proposing to use the second-to-last byte for instance ID:
This maintains backwards compatibility with existing eBPF worker routing (last byte) while adding instance routing.
Version Detection
Per @ravenblackx's point about distinguishing old vs new CID formats: I'm considering using a magic byte or bit pattern in the preserved first 4 bytes to indicate the format version. Alternatively, we could use CID length as an indicator (new format = length + 1).
Which approach do you prefer?
Implementation Scope
Given @danzh2010's comment that the generator choice depends on user needs, I'm planning to:
encode_instance_idconfig flagDoes this approach work, or would you prefer a separate generator extension?
BPF Maps
I'll use BPF maps for instance->socket mapping as suggested. The map would be:
The map would be populated when each instance starts listening.
filipcacky commentedon May 25, 2026
Hi @ravenblackx and @danzh2010. I've written a feature proposal here https://gist.github.com/filipcacky/7a65563665ac04a7605224d34499ee39.
I also have a working implementation at https://github.com/filipcacky/envoy/tree/ebpf_routing. It's a bit rough around the edges, lacks tests and breaks existing ones, and has a long way to go, but I think it's a good starting point for a discussion about this feature.
ravenblackx commentedon May 26, 2026
The proposal looks good to me, and a skim over the code looks like it's on a decent track.
I think the "known issue" is fine - some packet loss is expected anyway for http3 so a small amount of misdirection should be recoverable.
One question about this:
What happens if a parent process crashes before hot restart even begins?
(And which way are you leaning, option 1 or option 2?)
filipcacky commentedon May 27, 2026
The program and maps stay alive as long as at least one socket they're attached to remains open (or pinned maps/progs which also hold refcnt).
If we pin the program to bpffs and a process crashes, we need to clean up the map after loading or delete the pin before launching new process with the same pin path.
If its not pinned, the program and maps get cleaned up after the sockets are closed, the kernel handles that for us during a crash.
If it crashes after we've opened sockets in the same reuseport group, we hold the refcount to the program/maps and are responsible for cleanup ourselves.
Implemented pinning, SCM_RIGHTS and both options to get a better idea for the proppsal.
Leaning towards SCM_RIGHTS since it makes cleanup easier. Having the program pinned makes debugging less involved, you can just point bpftool at the pin path. It can stay as opt-in just for debugging, I think we'd have to add cleanup logic to the python hot restart script for production.
Option 1 seems awkward, requires the sentinel bit if we don't want to have a chance at dropping cons during hotrestart... Didn't think too much about all of the implications. With option 2 we can just use the CIDs as they are, adding another UDP listener alongside the QUIC listener seems fine, and writing it was straightforward.
There is still a question whether we want to pull in libbpf and libelf as dependencies. It makes loading the program and working with the maps easier, although its doable without - see quic_lb filter_ = {..., concurrency, ...};.
ravenblackx commentedon May 27, 2026
Would strongly recommend not relying on the python hot restart script doing cleanup, because different environments require different wrappers - the python hot restart script is more of a template than a solution. I think there's also a risky race, where it's possible for the wrapper to start up the new instance then some management process kills the old envoy instance before the new instance has transferred information. Specifically leading to this path. (Even if cleanup is added in that path there's still a small race danger where the parent gets killed after the connection is established but before the data is synchronized, but that window is much smaller. Hitting that extra-risk path already causes a deadlocked startup.)
It sounds like with SCM_RIGHTS maybe the cleanup of any previous instance could just be done as part of the initialization of the new instance, which would avoid all special casing of cleanup (the only "special case" being "there is something existing").
Re pulling in dependencies, I don't have enough information to make a recommendation - as a general thing I would say don't pull in a library unless it saves at least 50 lines of code per library, since the boilerplate for pulling in each library is close to that size in bzl files, and it also creates a maintenance burden [keeping version up to date] and a review blind spot [risk of upstream malicious changes that we don't review closely] and requires external license and security posture checks.
1 remaining item
ravenblackx commentedon May 27, 2026
Yep, sounds good to me (would still like some opinions from @danzh2010 but I haven't heard a peep from them in a while so maybe we're on our own).
Not sure if cleanup could be totally divested to the child instance in a way that might be simpler - for any "no hot restart" case the cleanup would happen automatically anyway on exit, and when there is a hot restart connection, an "everything old" cleanup could be triggered from multiple places - in the "failed to connect to the old instance" branch that implies the parent got killed at an inconvenient time, or in the "parent shutdown is complete" branch. But maybe that would be problematically worse, if the entries aren't getting cleaned up immediately as each connection closes, or if they are and double-cleanup on one connection would be a problem.
willianpaixao commentedon May 28, 2026
Hey @ravenblackx @danzh2010 @filipcacky,
Coming back to this thread. Thanks @filipcacky for the proposal and the prototype, that's a great starting point. Before we start cutting PRs I'd love to close out the few questions still floating around so we're all on the same page.
Option 1 vs Option 2 from the proposal. Sounds like @filipcacky is leaning Option 2 (SCM_RIGHTS, a separate UDP listener next to the QUIC one, CIDs used as is). Does that work for everyone, or are there concerns worth airing first?
Crash cleanup. Current thinking is SCM_RIGHTS with the new instance handling cleanup on init, though @ravenblackx also floated pushing all cleanup down to the child. Any preference between those two?
libbpf and libelf. Worth pulling in, or are we better off staying with the hand rolled approach the QUIC LB filter uses today? Curious if the savings actually clear @ravenblackx's rough 50 line per library bar.
@danzh2010, would really value your take here, especially on 1 and 2. No rush at all, just don't want to move forward without you since you had good input earlier on BPF maps and the generator side.
Happy to pitch in on implementation or reviews once we've aligned. Thanks all!
danzh2010 commentedon May 28, 2026
Sorry for the delayed response! Implementing eBPF supporting hot restart seem to add quite a bit complexity.
TBH, I don't see a clear reason why Option2 is better than Option1, given the additional listener and eBPF map look up and fallback. CID update in QUIC has race by nature. So to keep tracking all CIDs in use you need to keep some retired CIDs around for sometime. This is overly complicated to me for an eBPF program.
Can you do a comparison between these 2 options?
I don't care about the way of cleaning up the old instance as google doesn't use hot restart. So up-to your choice.
filipcacky commentedon May 29, 2026
Thanks @danzh2010.
Both options have two lookups.
The eBPF equivalent of cBPF's
return key % concurrency, which indexes theSO_REUSEPORTgroup,is AFAIK only
bpf_sk_select_reuseporton aREUSEPORT_SOCKARRAY,SOCKMAP, orSOCKHASH.IMO we still need one lookup for established connections and a fallback for new ones.
I went over the BPF map limitations again and found I made an error.
SOCKMAP/SOCKHASHcoexist fine, but pairing aREUSEPORT_SOCKARRAYwith any other map fails.I assumed this limitation applied to all BPF map types and didn't doublecheck.
Option1 and Option2 with separate sockets were designed to work around these limitations.
My main concern with Option1 was collisions on worker IDs. It's unlikely, but I wanted correctness regardless
(didn't like that a CID equal to a worker_id could get dropped during hot-restart).
Not needing two sockets per listener simplifies things,
we can use SOCKHASH for
CID -> socketand a SOCKMAP fallback forworker_id -> socket.SOCKHASHholds state to support multiple epochs,while
SOCKMAPis functionally equivalent to cBPF'sreturn key % concurrencyfor routing new connections to active sockets.I think we could skip the SOCKHASH when hotrestart isn't running and route packets only based on the SOCKMAP,
if there are any concerns about overhead of the hash lookup, would need to benchmark first.
Apologies for the confusion, I've dropped the additional listener, updated the proposal and the proof-of-concept code, and tested that it works.
QuicDispatcher::MaybeDispatchPacketdispatches packets based onreference_counted_session_map_.As I understand it, after
QuicDispatcher::OnConnectionIdRetiredis called,packets with a retired CID go through
QuicDispatcher::ProcessPacket,MaybeDispatchPacketreturns false,and they're dropped in
ProcessHeaderviaValidityChecks.I don't see why we'd need to keep the DCID around longer than that, can you please elaborate?
danzh2010 commentedon May 29, 2026
Just thinking aloud, can we encode all the states in CID, so that you don't need to deliberately maintain the CID to FD mapping? If the CID is encoded with Envoy instance ID, and the eBPF program maintain its own stable FD array along aside of REUSEPORT_SOCKARRAY, you can still use
key % concurrencyas the index to your own FD array for both existing and new connections. If the index->FD mapping is stable, the same algorithm can be used to dispatch both existing and new connections.This sounds more reasonable. Thanks for doing the researching.
If we only need to maintain the per CID -> FD map during hot restart, that'll be great. But I still think it's even better if we don't have to maintain this map.
And you can keep track of CID lifetime using these QUICHE interfaces to sync up with the internal
reference_counted_session_map_. But IMO it's overkill. And I don't know if updating the SOCKHASH for every CID updates is scalable or not.filipcacky commentedon May 29, 2026
Could do something like:
Tried it here and it seems doable: 00014ee
The JIT-ed program grew from 370 to 409 bytes, but that should more than pay for itself by removing the hash-map lookups and inserts, nice! Would be interesting to properly benchmark.
ravenblackx commentedon May 29, 2026
Re the cleanup question, to be clear I was floating the alternative cleanup option only as "maybe it would be easier/simpler" - I have no preference between the two ways, other than whichever is easier/simpler. i.e. I wasn't saying "please do it this way," I was saying only "you might find it's easier this way."
The main reason I think it might be easier being, cleanup in one thread [the one that if it doesn't survive means the whole process is terminated] is less likely to result in inconsistent state than split cleanup that could be half-interrupted by a poorly timed SIGKILL or similar hitting the parent instance.
But if it's fully cleaned up before the interprocess communication completes then worst case wouldn't be any worse than the current worst case, where a parent-kill during that communication window already results in a deadlocked child instance - so a split cleanup with the property "complete before communication completes" would also be fine.
filipcacky commentedon Jun 2, 2026
If we use
REUSEPORT_SOCKARRAY, then we don't need to worry about cleanup at all, the kernel removes the socket from the map once the socket is closed (this is where the limitation comes from).Worked on it a bit more and got LDS updates working aswell. Pre-allocate num_maps
REUSEPORT_SOCKARRAYs inside anARRAY_OF_MAPS, each sized up to max allowed concurrency. During an LDS update/hotrestart a listener grabs the next available map index.Routing long headers based on
DCID[0..4] % concurrencyand the current in-use map. For short headers, i just tagged the CID with map index and worker id. I don't like the worker id in CID though, would be probably better to store concurrency for each map in-program, so we can just doDCID[0..4] % concurrencyinstead of exposing the worker in CID.ggreenway commentedon Jun 23, 2026
A few questions:
Are you going to make this work for any connection ID generator, or only for the deterministic ID generator? If you're going to support the QUIC-LB generator, using the first 8 bytes of the CID for anything could lead to poor results in some configurations (in unencrypted mode, I believe the first 8 bytes could be the same for every CID). If you use the full 20-byte maximum CID, it'll work as expected. I'm not sure if doing something with the first 8 bytes is still part of the proposal or not.
What happens if (in a future version of Envoy) we need to change how QUIC packets are routed during a hot-restart? Eg, we're adding some new functionality, and need to encode the CID differently, or something similar?
Will the new encoding be always enabled, or configurable? If it's configurable but disabled and a hot-restart is performed, what happens?
filipcacky commentedon Jun 24, 2026
Planning a new CID generator based on deterministic, since the proposal needs another field on top of worker_id. I'm not too familiar with the QUIC-LB RFC, so I'd like to land this as a separate extension first, would be happy to help with quic_lb after if that's wanted.
The CID format can't change once the extension is running. We could tag CIDs with a version and branch to different handlers in the eBPF program (tail call on the version field) to let routing change across restarts, but that seems out of scope for now.
The plan is another extension, so it's always on within that extension. I hadn't considered swapping generators across a hot restart (deterministic → new, or none → new). Pre-existing connections carry CIDs without the routing fields, so they'd break. Seems complicated, probably best disallowed during hot restart/listener config swap.
Updated the feature proposal: https://gist.github.com/filipcacky/7a65563665ac04a7605224d34499ee39/ee06f3fb6e7fea9e163f4f46cabc92f73e13d5cd
ggreenway commentedon Jun 24, 2026
This makes sense to me as a new extension. Hot-restart is probably mutually exclusive with quic-lb, so that support isn't worth adding extra effort for.
ravenblackx commentedon Jun 24, 2026
We do hot restart and quic-lb (with a custom connection id generator in envoy) together. So breaking that combo would hurt our use.
ggreenway commentedon Jun 24, 2026
quic-lb is it's own connection id generator, which adds support for https://datatracker.ietf.org/doc/html/draft-ietf-quic-load-balancers. Is that really what you're doing, or are we confusing terms?
ravenblackx commentedon Jun 25, 2026
Ah, maybe not quite the same - but our setup does involve using some part of the connection id as a marker for which host to route to, which sounds pretty similar, so may be related enough to bear in mind at least. (But if it's just "I'll have to modify our connection id generator to accommodate the same thing" then that's expected and fine.)
ggreenway commentedon Jun 25, 2026
Right; I'm not saying we could/should never use these two things together, but that from my initial view they'd be less common to use together, so it's fine to wait for a need before trying to address it.