Skip to content

Commit

Permalink
Merge "Keeping on retrying zookeeper_init forever" into R3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Jan 31, 2017
2 parents 1aed849 + 379df67 commit 357dd76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
14 changes: 0 additions & 14 deletions src/zookeeper/test/zookeeper_client_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,6 @@ TEST_F(ZookeeperClientTest, Basic) {
EXPECT_FALSE(cImpl->IsConnected());
}

TEST_F(ZookeeperClientTest, ZookeeperInitFail) {
ZookeeperMockInterface *zmi(new ZookeeperMockInterface);
EXPECT_CALL(*zmi, ZooSetDebugLevel(_));
impl::ZookeeperClientImpl *cImpl(
new impl::ZookeeperClientImpl("Test", "127.0.0.1:2181", zmi));
std::auto_ptr<ZookeeperClient> client(CreateClient(cImpl));
std::string zk_lock_name("/test-lock");
ZookeeperLock zk_lock(client.get(), zk_lock_name.c_str());
std::string zk_lock_id(GetLockId(zk_lock));
EXPECT_CALL(*zmi, ZookeeperInit(StrEq("127.0.0.1:2181"), _, _, _, _, _));
EXPECT_FALSE(zk_lock.Lock());
EXPECT_FALSE(cImpl->IsConnected());
}

TEST_F(ZookeeperClientTest, ZooStateConnecting2Connect) {
ZookeeperMockInterface *zmi(new ZookeeperMockInterface);
EXPECT_CALL(*zmi, ZooSetDebugLevel(_));
Expand Down
19 changes: 4 additions & 15 deletions src/zookeeper/zookeeper_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,12 @@ bool ZookeeperClientImpl::Connect() {
NULL,
NULL,
0);
// Unfortunately, EINVAL is highly overloaded in zookeeper_init
// and can correspond to:
// (1) Empty / invalid 'host' string format.
// (2) Any getaddrinfo error other than EAI_NONAME,
// EAI_NODATA, and EAI_MEMORY are mapped to EINVAL.
// Either way, retrying is not problematic.
if (zk_handle_ == NULL && errno == EINVAL) {
ZOO_LOG(WARN, "zookeeper_init FAILED: (" << errno <<
"): retrying in 1 second");
sleep(1);
continue;
}
if (zk_handle_ == NULL) {
int zerrno(errno);
ZOO_LOG_ERR("zookeeper_init returned NULL zhandle: ("
<< zerrno << ")");
return false;
ZOO_LOG_ERR("zookeeper_init FAILED: (" << zerrno <<
"): servers: " << servers_ << " retrying in 1 second");
sleep(1);
continue;
}
// Block till session is connected
while (!connected_) {
Expand Down

0 comments on commit 357dd76

Please sign in to comment.