Skip to content

API to cancel grpc_resolve_address#27883

Merged
apolcyn merged 186 commits intogrpc:masterfrom
apolcyn:add_resolver_cancel_api
Dec 20, 2021
Merged

API to cancel grpc_resolve_address#27883
apolcyn merged 186 commits intogrpc:masterfrom
apolcyn:add_resolver_cancel_api

Conversation

@apolcyn
Copy link
Copy Markdown
Contributor

@apolcyn apolcyn commented Oct 29, 2021

Built on #27858 and #28332

This is needed to add cancellation support the grpc_httpcli_{get,post}, motivated to fix b/182302759

Reviewer notes:

  • The primary changes here are the edits of src/core/lib/iomgr/resolve_address.h, and then associated updates.

  • The implementation of cancellation for the native, getaddrinfo based resolvers is currently a no-op, and callers still need to wait the same amount of time as they normally would for their call to getaddrinfo to return, in the case that they "cancel" these resolutions.

  • There's a lot of test code moving around here because I centralized the fake UDP and TCP server that was used by some DNS tests and the alts_concurrent_connectivity_test, into the new test utility API in test/core/util/fake_udp_and_tcp_server.h. The only functional test changes in this PR are the edits to test/core/iomgr/resolve_address_test.cc.


This change is Reviewable

@apolcyn apolcyn added lang/core release notes: no Indicates if PR should not be in release notes labels Oct 29, 2021
Copy link
Copy Markdown
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

This is looking very good! Just a few minor issues left.

Please let me know if you have any questions. Thanks!

Reviewed 27 of 31 files at r6, 6 of 6 files at r7, all commit messages.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @apolcyn)


src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc, line 601 at r5 (raw file):

Previously, apolcyn wrote…

I think this would be a nice cleanup. However, this would add potentially user-visible behavioral changes to this PR (for example, servers could no longer bind to NETBIOS names on Windows, etc.).

Given those slight risks, I'd prefer to make that change as its own PR, so that it can be more easily identified and rolled back if it causes problems.

Added a TODO.

Good point about the behavior change. The TODO is fine.


src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc, line 580 at r7 (raw file):

  // gets the singleton instance, possibly creating it first
  static AresDNSResolver* GetOrCreate() {
    static AresDNSResolver* instance;

This can just be:

static AresDNSResolver* instance = new AresDNSResolver();
return instance;

Since it's static, the assignment will be evaluated only once.

Same thing in all implementations.


src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc, line 175 at r5 (raw file):

Previously, apolcyn wrote…

Good catch! fixed

Using std::move() inside of the lambda is still what we want, or else we're doing two copies instead of just the one that we can't avoid until we migrate to C++14. To make that possible, you just need to use the mutable keyword on the lambda.

[this, addresses_or]() mutable { OnResolvedLocked(std::move(addresses_or)); }

Later, when we can use C++14, this can become:

[this, addresses_or = std::move(addresses_or)]() mutable { OnResolvedLocked(std::move(addresses_or)); }

src/core/lib/iomgr/iomgr_custom.cc, line 23 at r7 (raw file):

#include "src/core/lib/iomgr/iomgr_custom.h"

#include "absl/functional/bind_front.h"

Doesn't look like this is used in this file.


src/core/lib/iomgr/resolve_address_custom.h, line 76 at r5 (raw file):

Previously, apolcyn wrote…

Done.

Instead of GetOrCreate() and set_vtable(), how about something like this:

// Creates the global custom resolver with the specified vtable.
static void CreateCustomResolver(const grpc_custom_resolver_vtable* vtable);

// Gets the global custom resolver.
static CustomDNSResolver* Get();

That way, it's not possible to change vtable after creation, which I think is the semantic we want here.

This will require having the static pointer outside of the Get() method, but I think that's a worthwhile trade-off in this case.


test/core/iomgr/resolve_address_test.cc, line 60 at r7 (raw file):

bool g_resolver_type_configured;

class ResolveAddressTest : public ::testing::TestWithParam<const char*> {

If we're using TestWithParam<>, don't we need an INSTANTIATE_TEST_SUITE_P() call somewhere for ResolveAddressTest, and then use TEST_P() instead of TEST_F() for the individual test cases? Otherwise, I'm not sure these tests are actually being run.

Copy link
Copy Markdown
Contributor Author

@apolcyn apolcyn left a comment

Choose a reason for hiding this comment

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

Thanks, I believe I've addressed comments again. PTAL

Reviewable status: 52 of 62 files reviewed, 5 unresolved discussions (waiting on @markdroth)


src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc, line 580 at r7 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

This can just be:

static AresDNSResolver* instance = new AresDNSResolver();
return instance;

Since it's static, the assignment will be evaluated only once.

Same thing in all implementations.

Done.


src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc, line 175 at r5 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Using std::move() inside of the lambda is still what we want, or else we're doing two copies instead of just the one that we can't avoid until we migrate to C++14. To make that possible, you just need to use the mutable keyword on the lambda.

[this, addresses_or]() mutable { OnResolvedLocked(std::move(addresses_or)); }

Later, when we can use C++14, this can become:

[this, addresses_or = std::move(addresses_or)]() mutable { OnResolvedLocked(std::move(addresses_or)); }

Done.


src/core/lib/iomgr/iomgr_custom.cc, line 23 at r7 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Doesn't look like this is used in this file.

Done.


src/core/lib/iomgr/resolve_address_custom.h, line 76 at r5 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

Instead of GetOrCreate() and set_vtable(), how about something like this:

// Creates the global custom resolver with the specified vtable.
static void CreateCustomResolver(const grpc_custom_resolver_vtable* vtable);

// Gets the global custom resolver.
static CustomDNSResolver* Get();

That way, it's not possible to change vtable after creation, which I think is the semantic we want here.

This will require having the static pointer outside of the Get() method, but I think that's a worthwhile trade-off in this case.

Done.


test/core/iomgr/resolve_address_test.cc, line 60 at r7 (raw file):

Previously, markdroth (Mark D. Roth) wrote…

If we're using TestWithParam<>, don't we need an INSTANTIATE_TEST_SUITE_P() call somewhere for ResolveAddressTest, and then use TEST_P() instead of TEST_F() for the individual test cases? Otherwise, I'm not sure these tests are actually being run.

I am seeing these test cases get ran. However, TestWithParam<> might be making things more complicated to inspect than is needed here.

Refactored to use TEST_F on all test cases.

Copy link
Copy Markdown
Member

@markdroth markdroth left a comment

Choose a reason for hiding this comment

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

This looks great!

Reviewed 9 of 10 files at r8, 1 of 1 files at r9, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @apolcyn)


test/core/iomgr/resolve_address_test.cc, line 60 at r7 (raw file):

Previously, apolcyn wrote…

I am seeing these test cases get ran. However, TestWithParam<> might be making things more complicated to inspect than is needed here.

Refactored to use TEST_F on all test cases.

Thanks, that's much more readable!

@apolcyn
Copy link
Copy Markdown
Contributor Author

apolcyn commented Dec 20, 2021

objc ios: #28389

basic tests php: #28390

pytnon linux/macos/windows/distribution: #28391

bazel rbe C++ macos actually passed, but are reported as failing here

All interop tests failing on python build issue: #28391

@apolcyn
Copy link
Copy Markdown
Contributor Author

apolcyn commented Dec 20, 2021

RBE msan C++ passed in https://source.cloud.google.com/results/invocations/b984a2b3-1d9e-4748-98bc-531c5da23f54/targets, but doesn't show up here on github

@apolcyn apolcyn merged commit 1a8d2b6 into grpc:master Dec 20, 2021
@copybara-service copybara-service bot added the imported Specifies if the PR has been imported to the internal repository label Dec 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bloat/medium imported Specifies if the PR has been imported to the internal repository lang/c++ lang/core perf-change/high release notes: yes Indicates if PR needs to be in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants