Skip to content

dns resolver: invoke resolve callback if not cancelled#10060

Merged
junr03 merged 2 commits intoenvoyproxy:masterfrom
junr03:destroy-callback
Feb 17, 2020
Merged

dns resolver: invoke resolve callback if not cancelled#10060
junr03 merged 2 commits intoenvoyproxy:masterfrom
junr03:destroy-callback

Conversation

@junr03
Copy link
Copy Markdown
Member

@junr03 junr03 commented Feb 14, 2020

Description:PendingResolutions get destroyed when complete or when c-ares sent ARES_EDESTRUCTION. Prior to #9899 ARES_EDESTRUCTION only happened when the resolver was destroyed. However, after #9899 the channel, and thus PendingResolutions can be destroyed, without the callback target being aware. This leads to potential use after free issues. This PR calls the resolve callback when the status received is ARES_EDESTRUCTION.
Risk Level: med
Testing: added test that reproduced segfault and passed after fix.

Signed-off-by: Jose Nino jnino@lyft.com

Signed-off-by: Jose Nino <jnino@lyft.com>
// ARES_ECONNREFUSED. If the PendingResolution has not been cancelled that means that the
// callback_ target _should_ still be around. In that case, raise the callback_ so the target
// can be done with this ActiveQuery and initiate a new one.
if (!cancelled_) {
Copy link
Copy Markdown
Member Author

@junr03 junr03 Feb 14, 2020

Choose a reason for hiding this comment

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

This approach relies on the fact that all callback targets (strict_dns_cluster, logical_dns_cluster, redis_cluster, dns_cache) cancel active queries in their destructors. This behavior is already used when a PendingResolution successfully completes. However, this is not an enforced contract.

I was debating about going further and move this to a similar pattern as the one in the init manager where the lifetimes of the target and the watcher are independent of each other and it is safe to call functions/callbacks on each other regardless of them being freed.

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.

I think this is fine but if you want to add a TODO to clean this up, up to you.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

👌 #10079

Signed-off-by: Jose Nino <jnino@lyft.com>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for fixing!

// ARES_ECONNREFUSED. If the PendingResolution has not been cancelled that means that the
// callback_ target _should_ still be around. In that case, raise the callback_ so the target
// can be done with this ActiveQuery and initiate a new one.
if (!cancelled_) {
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.

I think this is fine but if you want to add a TODO to clean this up, up to you.

@junr03 junr03 merged commit 5df4c55 into envoyproxy:master Feb 17, 2020
junr03 added a commit to envoyproxy/envoy-mobile that referenced this pull request Feb 18, 2020
Description: Bump the Envoy ref. This PR brings in the relevant updates to Envoy Mobile:

    envoyproxy/envoy#10060 which Fixes #687

Risk Level: low
Testing: unit test in Envoy, Envoy Mobile local build and CI

Fixes #687

Signed-off-by: Jose Nino <jnino@lyft.com>
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: Bump the Envoy ref. This PR brings in the relevant updates to Envoy Mobile:

    #10060 which Fixes #687

Risk Level: low
Testing: unit test in Envoy, Envoy Mobile local build and CI

Fixes #687

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: Bump the Envoy ref. This PR brings in the relevant updates to Envoy Mobile:

    #10060 which Fixes #687

Risk Level: low
Testing: unit test in Envoy, Envoy Mobile local build and CI

Fixes #687

Signed-off-by: Jose Nino <jnino@lyft.com>
Signed-off-by: JP Simard <jp@jpsim.com>
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.

2 participants