Skip to content

Commit

Permalink
[#5561] Attach CDS to client initializer thread
Browse files Browse the repository at this point in the history
Summary:
Async client initializer uses separate thread to perform it's job.
This thread does not have CDS attached, so it crashes in case of call to RPC thread pool.
Such call is possible when master resolution failed and such result already stored in DNS cache.

Test Plan:
ybd --gtest_filter ClientTest.BadMasterAddress
Jenkins: rebase: 2.1

Reviewers: timur

Reviewed By: timur

Subscribers: ybase

Differential Revision: https://phabricator.dev.yugabyte.com/D9333
  • Loading branch information
spolitov committed Sep 9, 2020
1 parent d19c973 commit 174318f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/yb/client/async_initializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ YBClient* AsyncClientInitialiser::client() const {
}

void AsyncClientInitialiser::InitClient() {
CDSAttacher attacher;

LOG(INFO) << "Starting to init ybclient";
while (!stopping_) {
auto result = client_builder_.Build(messenger_);
Expand Down
29 changes: 29 additions & 0 deletions src/yb/client/client-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <glog/stl_logging.h>

#include "yb/client/callbacks.h"
#include "yb/client/async_initializer.h"
#include "yb/client/client.h"
#include "yb/client/client-internal.h"
#include "yb/client/client-test-util.h"
Expand Down Expand Up @@ -86,6 +87,7 @@

#include "yb/util/capabilities.h"
#include "yb/util/metrics.h"
#include "yb/util/net/dns_resolver.h"
#include "yb/util/net/sockaddr.h"
#include "yb/util/status.h"
#include "yb/util/stopwatch.h"
Expand Down Expand Up @@ -2240,5 +2242,32 @@ TEST_F(ClientTest, GetNamespaceInfo) {
ASSERT_TRUE(resp.colocated());
}

TEST_F(ClientTest, BadMasterAddress) {
auto messenger = ASSERT_RESULT(CreateMessenger("test-messenger"));
auto host = "should.not.resolve";

// Put host entry in cache.
ASSERT_NOK(messenger->resolver().Resolve(host));

{
struct TestServerOptions : public server::ServerBaseOptions {
};
TestServerOptions opts;
auto master_addr = std::make_shared<server::MasterAddresses>();
// Put several hosts, so resolve would take place.
master_addr->push_back({HostPort(host, 1)});
master_addr->push_back({HostPort(host, 2)});
opts.SetMasterAddresses(master_addr);

AsyncClientInitialiser async_init(
"test-client", /* num_reactors= */ 1, /* timeout_seconds= */ 1, "UUID", &opts,
/* metric_entity= */ nullptr, /* parent_mem_tracker= */ nullptr, messenger.get());
async_init.Start();
async_init.get_client_future().wait_for(1s);
}

messenger->Shutdown();
}

} // namespace client
} // namespace yb

0 comments on commit 174318f

Please sign in to comment.