Skip to content

Commit

Permalink
Merge pull request #278 from wareczek/feature/response_counter_limit
Browse files Browse the repository at this point in the history
ability to overwrite default response counter limit (10)
  • Loading branch information
DavidVujic authored Jun 8, 2021
2 parents 81b791c + ff22897 commit 06d2580
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ Have a look at the code in the [examples](./examples) folder: with __master__, _

### Input Parameters

* options : object. valid keys: { connect, timeout, debug_level, host_order_deterministic, data_as_buffer}
* options : object. valid keys: { connect, timeout, debug_level, host_order_deterministic, data_as_buffer, response_counter_limit }
* path : string
* data : string or Buffer
* flags : int32. Supported:
Expand Down
9 changes: 8 additions & 1 deletion src/node-zk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class ZooKeeper: public Nan::ObjectWrap {
LOG_ERROR("yield:zookeeper_process returned an error: %d - %s\n", rc, zerror(rc));
}

if (zk->noResponseCounter > 10) {
if (zk->noResponseCounter > zk->responseCounterLimit) {
LOG_ERROR("yield:zookeeper_process returned no response too many times: %d\n", zk->noResponseCounter);
zk->realClose(ZOO_EXPIRED_SESSION_STATE);
return;
Expand Down Expand Up @@ -466,6 +466,11 @@ class ZooKeeper: public Nan::ObjectWrap {
ZooKeeper *zk = ObjectWrap::Unwrap<ZooKeeper>(info.This());
assert(zk);

int32_t response_counter_limit = toInt(arg, LOCAL_STRING("response_counter_limit"));
if (response_counter_limit > 0) {
zk->responseCounterLimit = response_counter_limit;
}

if (!zk->realInit(*_hostPort, session_timeout, &local_client)) {
RETURN_VALUE(info, Nan::ErrnoException(errno, "zookeeper_init", "failed to init", __FILE__));
} else {
Expand Down Expand Up @@ -1119,6 +1124,7 @@ class ZooKeeper: public Nan::ObjectWrap {
ZERO_MEM (zk_io);
ZERO_MEM (zk_timer);
is_closed = false;
responseCounterLimit = 10;
}
private:
zhandle_t *zhandle;
Expand All @@ -1138,6 +1144,7 @@ class ZooKeeper: public Nan::ObjectWrap {
int64_t last_activity; // time of last zookeeper event loop activity
bool is_closed;
int noResponseCounter;
int responseCounterLimit;
};

} // namespace "zk"
Expand Down

0 comments on commit 06d2580

Please sign in to comment.