Skip to content

Commit

Permalink
ZOOKEEPER-3095: Connect string fix for non-existent hosts
Browse files Browse the repository at this point in the history
ZKPatch: eda58d9970c76831046ddc45251c9b110856836e (extract)

Author: Jeelani Mohamed Abdul Khader <[email protected]>

Reviewers: Benjamin Reed <[email protected]>

Closes #579 from mjeelanimsft/connect-string-fix-for-non-existent-hosts
  • Loading branch information
Jeelani Mohamed Abdul Khader authored and breed committed Jul 28, 2018
1 parent 2a372fc commit 932fee8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/c/src/zookeeper.c
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@ static int resolve_hosts(const zhandle_t *zh, const char *hosts_in, addrvec_t *a
LOG_ERROR(LOGCALLBACK(zh), "getaddrinfo: %s\n", strerror(errno));
#endif
rc=ZSYSTEMERROR;
goto fail;
goto next;
}
}

Expand Down Expand Up @@ -842,11 +842,16 @@ static int resolve_hosts(const zhandle_t *zh, const char *hosts_in, addrvec_t *a
}

freeaddrinfo(res0);

next:
host = strtok_r(0, ",", &strtok_last);
}
#endif
}
if (avec->count == 0) {
rc = ZSYSTEMERROR; // not a single host resolved
goto fail;
}

free(hosts);

if(!disable_conn_permute){
Expand Down
13 changes: 12 additions & 1 deletion src/c/tests/TestClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ class Zookeeper_simpleSystem : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testAsyncWatcherAutoReset);
CPPUNIT_TEST(testDeserializeString);
CPPUNIT_TEST(testFirstServerDown);
CPPUNIT_TEST(testNonexistentHost);
#ifdef THREADED
CPPUNIT_TEST(testNullData);
#ifdef ZOO_IPV6_ENABLED
Expand Down Expand Up @@ -325,7 +326,17 @@ class Zookeeper_simpleSystem : public CPPUNIT_NS::TestFixture
CPPUNIT_ASSERT(zk != 0);
CPPUNIT_ASSERT(ctx.waitForConnected(zk));
}


/* Checks that a non-existent host will not block the connection*/
void testNonexistentHost() {
char hosts[] = "jimmy:5555,127.0.0.1:22181";
watchctx_t ctx;
zoo_deterministic_conn_order(true /* disable permute */);
zhandle_t *zh = createClient(hosts, &ctx);
CPPUNIT_ASSERT(ctx.waitForConnected(zh));
zoo_deterministic_conn_order(false /* enable permute */);
}

/** this checks for a deadlock in calling zookeeper_close and calls from a default watcher that might get triggered just when zookeeper_close() is in progress **/
void testHangingClient() {
int zrc = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/c/tests/zkServer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fi

if [ "x${base_dir}" == "x" ]
then
zk_base="../../"
zk_base="../../../"
else
zk_base="${base_dir}"
fi
Expand Down

0 comments on commit 932fee8

Please sign in to comment.