Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ability to overwrite default response counter limit (10) #278

Merged
merged 2 commits into from
Jun 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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