Skip to content

CDS: Fix member order in CdsApiImpl#15808

Merged
mattklein123 merged 1 commit intoenvoyproxy:mainfrom
kinvolk:krnowak/member-order-fix
Apr 1, 2021
Merged

CDS: Fix member order in CdsApiImpl#15808
mattklein123 merged 1 commit intoenvoyproxy:mainfrom
kinvolk:krnowak/member-order-fix

Conversation

@krnowak
Copy link
Copy Markdown
Contributor

@krnowak krnowak commented Apr 1, 2021

Commit Message:
The scope_ member is passed to subscription_ as a reference, so scope_
should live longer than subscription_, otherwise we risk a use of a
dangling reference to scope_ inside subscription_. To make sure that
scope_ lives longer than subscription_ order scope_ before
subscription_. That way scope_ is constructed before subscription_ and
destroyed after it.

Additional Description:
I found it tricky to write a test for this issue. I had crashes in OdCdsApiImpl which had the same issue (see the backtrace), but not with CdsApiImpl. The issue was quite involved (it was crashing on using an already-freed counter somewhere within NewGrpcMuxImpl because of NewGrpcMuxImpl::WatchImpl begin destroyed (caused by destruction of GrpcSubscriptionImpl). It does not look like a material for a unit test. Also, such a test could be flaky because of use-after-free being undefined behaviour.

Risk Level:
Low.

Testing:
As a part of #15523.

Docs Changes:
N/A.

Release Notes:
N/A.

Platform Specific Features:
N/A.

The scope_ member is passed to subscription_ as a reference, so scope_
should live longer than subscription_, otherwise we risk a use of a
dangling reference to scope_ inside subscription_. To make sure that
scope_ lives longer than subscription_ order scope_ before
subscription_. That way scope_ is constructed before subscription_ and
destroyed after it.

Signed-off-by: Krzesimir Nowak <krzesimir@kinvolk.io>
@repokitteh-read-only
Copy link
Copy Markdown

Hi @krnowak, welcome and thank you for your contribution.

We will try to review your Pull Request as quickly as possible.

In the meantime, please take a look at the contribution guidelines if you have not done so already.

🐱

Caused by: #15808 was opened by krnowak.

see: more, trace.

@mattklein123
Copy link
Copy Markdown
Member

@jmarantz can you take a quick look at this? At a high level this make sense to me and I'm OK without an explicit test (though it seems like we should be able to do it with mocking), but I'm curious why we haven't seen any issues before. I'm guessing it's because somehow we avoid issues with the global CDS and shutdown?

Copy link
Copy Markdown
Contributor

@jmarantz jmarantz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent of whether there is a current crash, this change looks correct to me, and I'm inclined to approve it.

@mattklein123 mattklein123 merged commit 9e657c1 into envoyproxy:main Apr 1, 2021
void runInitializeCallbackIfAny();

ClusterManager& cm_;
Stats::ScopePtr scope_;
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.

Would be good to have a test to detect if member order ever regresses.

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.

Yes I agree. I think this should be possible with mocks per above. cc @krnowak if you could follow up and add this.

@krnowak krnowak deleted the krnowak/member-order-fix branch October 21, 2021 12:46
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.

4 participants