DNSResolver cancellation continued (followup to #29581) (#29631)

pull/29304/head
AJ Heller 3 years ago committed by GitHub
parent 941e21b3b3
commit 075e84314d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc
  2. 6
      src/core/lib/http/httpcli.cc
  3. 11
      test/core/iomgr/resolve_address_test.cc

@ -500,6 +500,9 @@ class AresDNSResolver : public DNSResolver {
MutexLock lock(&mu_);
if (!open_requests_.contains(handle)) {
// Unknown request, possibly completed already, or an invalid handle.
GRPC_CARES_TRACE_LOG(
"AresDNSResolver:%p attempt to cancel unknown TaskHandle:%s", this,
HandleToString(handle).c_str());
return false;
}
auto* request = reinterpret_cast<AresRequest*>(handle.keys[0]);

@ -219,6 +219,12 @@ void HttpRequest::Orphan() {
"cancelled during DNS resolution"));
Unref();
} else if (connecting_) {
// gRPC's TCP connection establishment API doesn't currently have
// a mechanism for cancellation. So invoke the user callback now. The TCP
// connection will eventually complete (at least within its deadline), and
// we'll simply unref ourselves at that point.
// TODO(apolcyn): fix this to cancel the TCP connection attempt when
// an API to do so exists.
Finish(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
"HTTP request cancelled during TCP connection establishment",
&overall_error_, 1));

@ -370,6 +370,17 @@ TEST_F(ResolveAddressTest, ImmediateCancel) {
PollPollsetUntilRequestDone();
}
// Attempt to cancel a request after it has completed.
TEST_F(ResolveAddressTest, CancelDoesNotSucceed) {
grpc_core::ExecCtx exec_ctx;
auto request_handle = grpc_core::GetDNSResolver()->ResolveName(
"localhost:1", "1", pollset_set(),
absl::bind_front(&ResolveAddressTest::MustSucceed, this));
grpc_core::ExecCtx::Get()->Flush();
PollPollsetUntilRequestDone();
ASSERT_FALSE(grpc_core::GetDNSResolver()->Cancel(request_handle));
}
namespace {
int g_fake_non_responsive_dns_server_port;

Loading…
Cancel
Save