Skip to content

http: wire ConnectionLifetimeCallbacks into pool connection events - #43702

Merged
agrawroh merged 2 commits into
envoyproxy:mainfrom
aakugan:lifetimecallbacks-notify
Apr 13, 2026
Merged

agrawroh merged 2 commits into
envoyproxy:mainfrom
aakugan:lifetimecallbacks-notify

Conversation

@aakugan

@aakugan aakugan commented Mar 1, 2026 •

Copy link
Copy Markdown
Contributor

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). 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

  • 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

@ggreenway ggreenway left a comment

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.

Added a couple of drive-by comments

Comment thread envoy/http/conn_pool.h Outdated
}

protected:
OptRef<ConnectionLifetimeCallbacks> callbacks_;

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.

Move all implementation and data out of the interface and into the implementation

Comment thread source/common/http/conn_pool_base.h Outdated

// Override to provide the lifetimeCallbacks.
void onEvent(Network::ConnectionEvent event) override {
if (event == Network::ConnectionEvent::Connected ||

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.

Move implementation into .cc file

@aakugan
aakugan force-pushed the lifetimecallbacks-notify branch 2 times, most recently from 00c217d to 196381e Compare March 4, 2026 07:10
@aakugan
aakugan requested a review from ggreenway March 4, 2026 12:14
@yanavlasov

Copy link
Copy Markdown
Contributor

@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

@aakugan

aakugan commented Mar 5, 2026

Copy link
Copy Markdown
Contributor Author

Ya so it looks like there is pre existing flake following it up here
#43790

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?

@agrawroh

Copy link
Copy Markdown
Member

@aakugan We might need to fix the flaks (separately) or otherwise CI won't let you ship this.

/wait

@paul-r-gall

Copy link
Copy Markdown
Contributor

/retest

@aakugan
aakugan force-pushed the lifetimecallbacks-notify branch from 4f451f8 to e390f16 Compare March 18, 2026 05:53
@aakugan

aakugan commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

/retest

2 similar comments
@aakugan

aakugan commented Mar 18, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@aakugan

aakugan commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@aakugan
aakugan force-pushed the lifetimecallbacks-notify branch from e390f16 to 2ae00ea Compare March 22, 2026 10:47
@aakugan

aakugan commented Mar 22, 2026

Copy link
Copy Markdown
Contributor Author

/retest

@aakugan

aakugan commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

@yanavlasov @ggreenway can you please take a look the ci is passing now.
Thanks!

@tonya11en

Copy link
Copy Markdown
Member

@yanavlasov PTAL

@yanavlasov

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot 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.

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.

@envoyproxy envoyproxy deleted a comment from gemini-code-assist Bot Apr 10, 2026
@envoyproxy envoyproxy deleted a comment from gemini-code-assist Bot Apr 10, 2026
@envoyproxy envoyproxy deleted a comment from gemini-code-assist Bot Apr 10, 2026
@envoyproxy envoyproxy deleted a comment from gemini-code-assist Bot Apr 10, 2026
@agrawroh
agrawroh merged commit 5a363b3 into envoyproxy:main Apr 13, 2026
29 checks passed
Copilot AI pushed a commit to mmorel-35/envoy that referenced this pull request Apr 13, 2026
…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]>
krinkinmu pushed a commit to grnmeira/envoy that referenced this pull request Apr 20, 2026
…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()) {

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.

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.

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 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());

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.

why are we calling Draining when the event is LocalClose and RemoteClose?

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.

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.

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.

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.

botengyao added a commit that referenced this pull request May 14, 2026
#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]>
jiaweiw02 pushed a commit to jiaweiw02/envoy that referenced this pull request May 15, 2026
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]>
alrzazz pushed a commit to alrzazz/envoy that referenced this pull request May 20, 2026
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants