Repository navigation
http: wire ConnectionLifetimeCallbacks into pool connection events - #43702
Conversation
ggreenway
left a comment
There was a problem hiding this comment.
Added a couple of drive-by comments
| } | ||
|
|
||
| protected: | ||
| OptRef<ConnectionLifetimeCallbacks> callbacks_; |
There was a problem hiding this comment.
Move all implementation and data out of the interface and into the implementation
|
|
||
| // Override to provide the lifetimeCallbacks. | ||
| void onEvent(Network::ConnectionEvent event) override { | ||
| if (event == Network::ConnectionEvent::Connected || |
There was a problem hiding this comment.
Move implementation into .cc file
00c217d to
196381e
Compare
|
@aakugan can you check if ASAN failure is legit, please: https://github.com/envoyproxy/envoy/actions/runs/22659006942/job/65674847129#step:19:750 /wait-any |
|
Ya so it looks like there is pre existing flake following it up here Btw I see other tests failing which pass locally and seem unrelated to my change, am I correct in assuming I can ignore those failures? |
|
@aakugan We might need to fix the flaks (separately) or otherwise CI won't let you ship this. /wait |
196381e to
4f451f8
Compare
|
/retest |
4f451f8 to
e390f16
Compare
|
/retest |
2 similar comments
|
/retest |
|
/retest |
Signed-off-by: aakugan <[email protected]>
Signed-off-by: aakugan <[email protected]>
e390f16 to
2ae00ea
Compare
|
/retest |
|
@yanavlasov @ggreenway can you please take a look the ci is passing now. |
|
@yanavlasov PTAL |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to track connection lifetime events (opening and draining) across different HTTP connection pool implementations, including the connectivity grid. It adds a ConnectionLifetimeCallbacks interface and integrates it into the base connection pool classes to allow upstream components, like load balancers, to monitor individual connection states. The review feedback correctly identifies a potential issue where lifecycle events could be fired multiple times due to overlapping network events (e.g., receiving both a GOAWAY and a connection close). It is recommended to implement boolean guards within MultiplexedActiveClientBase to ensure onConnectionOpen and onConnectionDraining are each invoked exactly once per connection, and to update the corresponding test expectations to reflect this single-fire behavior.
…nvoyproxy#43702) ## Commit Message http: wire ConnectionLifetimeCallbacks into pool connection events ## Description Wires up the `ConnectionLifetimeCallbacks` interface that is there but is not connected to actual connection events from what I see at least. The cluster manager now passes the LB's callbacks into each HTTP pool at creation time, and `MultiplexedActiveClientBase` fires them on Connected, Close, and GOAWAY events. Primary motivation: allows the reverse tunnel cluster's LB to detect GOAWAY and report it to the tunnel reporter ([raw example](aakugan@31094c9)). Also applicable to DFP clusters for connection coalescing awareness from what I [see](envoyproxy#17874). ## Risk Level Should be low. Additive-only changes to production code. Callbacks are no-ops unless explicitly set by the LB. No behavior change for existing clusters. ## Testing - HTTP/2 conn pool unit tests (7 tests): no-op without callbacks, Connected/RemoteClose/LocalClose with arg verification, GOAWAY with active streams, idle GOAWAY, callback replacement. - HTTP/3 conn pool unit test: Connected + idle GOAWAY through `MultiplexedActiveClientBase`. - Cluster manager unit tests: verifies `setLifetimeCallbacks` is called on pool creation. ## Docs Changes N/A ## Release Notes N/A --------- Signed-off-by: aakugan <[email protected]> Co-authored-by: mmorel-35 <[email protected]>
…nvoyproxy#43702) ## Commit Message http: wire ConnectionLifetimeCallbacks into pool connection events ## Description Wires up the `ConnectionLifetimeCallbacks` interface that is there but is not connected to actual connection events from what I see at least. The cluster manager now passes the LB's callbacks into each HTTP pool at creation time, and `MultiplexedActiveClientBase` fires them on Connected, Close, and GOAWAY events. Primary motivation: allows the reverse tunnel cluster's LB to detect GOAWAY and report it to the tunnel reporter ([raw example](aakugan@31094c9)). Also applicable to DFP clusters for connection coalescing awareness from what I [see](envoyproxy#17874). ## Risk Level Should be low. Additive-only changes to production code. Callbacks are no-ops unless explicitly set by the LB. No behavior change for existing clusters. ## Testing - HTTP/2 conn pool unit tests (7 tests): no-op without callbacks, Connected/RemoteClose/LocalClose with arg verification, GOAWAY with active streams, idle GOAWAY, callback replacement. - HTTP/3 conn pool unit test: Connected + idle GOAWAY through `MultiplexedActiveClientBase`. - Cluster manager unit tests: verifies `setLifetimeCallbacks` is called on pool creation. ## Docs Changes N/A ## Release Notes N/A --------- Signed-off-by: aakugan <[email protected]>
| } | ||
|
|
||
| void HttpConnPoolImplBase::onConnectionOpen(const Network::Connection& connection) { | ||
| if (callbacks_.has_value()) { |
There was a problem hiding this comment.
Hi, this is not enough and we are experiencing crashes, and callbacks_ can be a dangling ptr when the cluster is destroyed.
When a dynamic cluster is removed, its LoadBalancer (which implements the new ConnectionLifetimeCallbacks) is destroyed immediately, but its associated Connection Pools are kept alive to gracefully finish active requests.
Because the pools track the callbacks using OptRef (a non-owning raw pointer without lifetime tracking), asynchronous connection closures that happen after the cluster is removed attempt to fire onConnectionDraining to the dangling LoadBalancer pointer, causing a segmentation fault.
one way to fix is to reset the callback in the connection pool's drainConnections(DrainAndDelete) method, we nullify the dangling pointer at the exact moment the LoadBalancer is destroyed, ensuring any subsequent asynchronous connection events are safely ignored.
Also we need to evaluate the smart pointer solution rather than the OptRef.
There was a problem hiding this comment.
Thanks for the detailed writeup. This was my oversight and I am sorry for that. I'm working on a new PR that uses weak_ptr instead of OptRef so the pool can safely detect if the LB has already been destroyed before firing callbacks. Should have it up early next week with test coverage for the dynamic cluster removal path.
| parent().onConnectionOpen(codec_client_->connection()); | ||
| } else if (event == Network::ConnectionEvent::LocalClose || | ||
| event == Network::ConnectionEvent::RemoteClose) { | ||
| parent().onConnectionDraining(codec_client_->connection()); |
There was a problem hiding this comment.
why are we calling Draining when the event is LocalClose and RemoteClose?
There was a problem hiding this comment.
Looking at the interface, it may be a poorly named function. The docs say it should be called when the pool should no longer be used, which is the case here.
There was a problem hiding this comment.
The onConnectionDraining doc says "called when a connection is draining and may no longer be used for requests." My read was that any connection becoming unusable should be surfaced through it so the LB can act on it, including closed connections that skipped the drain path. That said, I agree a separate method makes this clearer. I'm planning to add a dedicated onConnectionClose for hard closes so onConnectionDraining stays GOAWAY-only.
#45056) …vents (#43702)" This reverts commit 5a363b3. <!-- !!!ATTENTION!!! If you are fixing **any** crash or **any** potential security issue, **do not open a pull request**. Instead, please [open a GitHub Security Advisory](https://github.com/envoyproxy/envoy/security/advisories/new) (preferred). Alternatively, you may email [email protected]. Thank you in advance for helping to keep Envoy secure. !!!ATTENTION!!! For an explanation of how to fill out the fields, please see the relevant section in [PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md) !!!ATTENTION!!! Please check the [use of generative AI policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41). You may use generative AI only if you fully understand the code. You need to disclose this usage in the PR description to ensure transparency. --> The above PR is causing multiple issues on the callback management, and the impl of `onConnectionOpen()` and `onConnectionDrain()`. Will revert now until we fully fix or understand it. Commit Message: Additional Description: Risk Level: Testing: Docs Changes: Release Notes: Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] Signed-off-by: Boteng Yao <[email protected]>
envoyproxy#45056) …vents (envoyproxy#43702)" This reverts commit 5a363b3. <!-- !!!ATTENTION!!! If you are fixing **any** crash or **any** potential security issue, **do not open a pull request**. Instead, please [open a GitHub Security Advisory](https://github.com/envoyproxy/envoy/security/advisories/new) (preferred). Alternatively, you may email [email protected]. Thank you in advance for helping to keep Envoy secure. !!!ATTENTION!!! For an explanation of how to fill out the fields, please see the relevant section in [PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md) !!!ATTENTION!!! Please check the [use of generative AI policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41). You may use generative AI only if you fully understand the code. You need to disclose this usage in the PR description to ensure transparency. --> The above PR is causing multiple issues on the callback management, and the impl of `onConnectionOpen()` and `onConnectionDrain()`. Will revert now until we fully fix or understand it. Commit Message: Additional Description: Risk Level: Testing: Docs Changes: Release Notes: Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] Signed-off-by: Boteng Yao <[email protected]> Signed-off-by: Jiawei Wu <[email protected]>
envoyproxy#45056) …vents (envoyproxy#43702)" This reverts commit 5a363b3. <!-- !!!ATTENTION!!! If you are fixing **any** crash or **any** potential security issue, **do not open a pull request**. Instead, please [open a GitHub Security Advisory](https://github.com/envoyproxy/envoy/security/advisories/new) (preferred). Alternatively, you may email [email protected]. Thank you in advance for helping to keep Envoy secure. !!!ATTENTION!!! For an explanation of how to fill out the fields, please see the relevant section in [PULL_REQUESTS.md](https://github.com/envoyproxy/envoy/blob/main/PULL_REQUESTS.md) !!!ATTENTION!!! Please check the [use of generative AI policy](https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md?plain=1#L41). You may use generative AI only if you fully understand the code. You need to disclose this usage in the PR description to ensure transparency. --> The above PR is causing multiple issues on the callback management, and the impl of `onConnectionOpen()` and `onConnectionDrain()`. Will revert now until we fully fix or understand it. Commit Message: Additional Description: Risk Level: Testing: Docs Changes: Release Notes: Platform Specific Features: [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] Signed-off-by: Boteng Yao <[email protected]> Signed-off-by: Alireza <[email protected]>
Commit Message
http: wire ConnectionLifetimeCallbacks into pool connection events
Description
Wires up the
ConnectionLifetimeCallbacksinterface that is there but is not connected to actual connection events from what I see at least. The cluster manager now passes the LB's callbacks into each HTTP pool at creation time, andMultiplexedActiveClientBasefires them on Connected, Close, and GOAWAY events.Primary motivation: allows the reverse tunnel cluster's LB to detect GOAWAY and report it to the tunnel reporter (raw example). Also applicable to DFP clusters for connection coalescing awareness from what I see.
Risk Level
Should be low. Additive-only changes to production code. Callbacks are no-ops unless explicitly set by the LB. No behavior change for existing clusters.
Testing
MultiplexedActiveClientBase.setLifetimeCallbacksis called on pool creation.Docs Changes
N/A
Release Notes
N/A