Skip to content

Conversation

@wdauchy
Copy link
Contributor

@wdauchy wdauchy commented Nov 25, 2025

Commit Message:
The OdCdsApiHandleImpl destructor can be invoked on worker threads when filters are removed (e.g., during VHDS filter updates). When the last reference to an OdCdsApiSharedPtr is destroyed on a worker thread, the subscription cleanup code attempts to run on the wrong thread, causing an assertion failure or SIGABRT since subscription operations must execute on the main thread.

This fix adds a destructor to OdCdsApiHandleImpl that checks if destruction is happening on a worker thread. If so, it dispatches the OdCdsApiSharedPtr destruction to the main thread dispatcher via a lambda, ensuring the subscription is properly cleaned up on the thread where it was created.

The fix follows the same pattern used elsewhere in Envoy (e.g., ThreadLocal::SlotImpl destructor) for cross-thread cleanup operations.

Additional Description:

Note: A longer-term optimization could cache and reuse OdCDS handles in ClusterManager with reference counting and deferred cleanup, avoiding unnecessary subscription teardown/recreation during filter rotations. This is tracked by the existing TODO in allocateOdCdsApi().

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:]

@repokitteh-read-only
Copy link

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #42253 was opened by wdauchy.

see: more, trace.

@wdauchy wdauchy force-pushed the odcds branch 5 times, most recently from 15f79be to b782257 Compare November 25, 2025 19:14
@wdauchy wdauchy marked this pull request as ready for review November 25, 2025 19:50
@botengyao
Copy link
Member

botengyao commented Nov 26, 2025

@adisuissa as our xDS expert

@wdauchy wdauchy force-pushed the odcds branch 3 times, most recently from 058d2f6 to 95ede76 Compare November 27, 2025 12:19
The OdCdsApiHandleImpl destructor can be invoked on worker threads when
filters are removed (e.g., during VHDS filter updates). When the last
reference to an OdCdsApiSharedPtr is destroyed on a worker thread, the
subscription cleanup code attempts to run on the wrong thread, causing
an assertion failure or SIGABRT since subscription operations must
execute on the main thread.

This fix adds a destructor to OdCdsApiHandleImpl that checks if destruction
is happening on a worker thread. If so, it dispatches the OdCdsApiSharedPtr
destruction to the main thread dispatcher via a lambda, ensuring the
subscription is properly cleaned up on the thread where it was created.

The fix follows the same pattern used elsewhere in Envoy (e.g.,
ThreadLocal::SlotImpl destructor) for cross-thread cleanup operations.

Note: A longer-term optimization could cache and reuse OdCDS handles in
ClusterManager with reference counting and deferred cleanup, avoiding
unnecessary subscription teardown/recreation during filter rotations.
This is tracked by the existing TODO in allocateOdCdsApi().

Signed-off-by: William Dauchy <[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.

3 participants