Skip to content

Commit f14c15d

Browse files
committed
Fix client socket when closing and error handling
1 parent e498bf5 commit f14c15d

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ node_modules
44
*.swo
55
test/data.txt
66
docs
7+
.idea

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Follow the [instructions](http://kafka.apache.org/documentation.html#quickstart)
2020
* `connectionString`: Zookeeper connection string, default `localhost:2181/`
2121
* `clientId`: This is a user-supplied identifier for the client application, default `kafka-node-client`
2222
* `zkOptions`: **Object**, Zookeeper options, see [node-zookeeper-client](https://github.com/alexguan/node-zookeeper-client#client-createclientconnectionstring-options)
23-
* `noAckBatchOptions`: **Object**, when requireAcks is disabled on Producer side we can define the batch properties, 'noAckBatchSize' in bytes and 'noAckBatchAge' in milliseconds. The default value is `{ noAckBatchSize: 500, noAckBatchAge: 300 }`
23+
* `noAckBatchOptions`: **Object**, when requireAcks is disabled on Producer side we can define the batch properties, 'noAckBatchSize' in bytes and 'noAckBatchAge' in milliseconds. The default value is `{ noAckBatchSize: null, noAckBatchAge: null }` and it acts as if there was no batch
2424

2525
### close(cb)
2626
Closes the connection to Zookeeper and the brokers so that the node process can exit gracefully.

lib/client.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,13 @@ Client.prototype.sendToBroker = function (payloads, encoder, decoder, cb) {
413413
var correlationId = this.nextId();
414414
var request = encoder.call(null, this.clientId, correlationId, payloads[leader]);
415415
var broker = this.brokerForLeader(leader, longpolling);
416-
if (broker.error || broker.closing) {
416+
if (broker.socket.error || broker.socket.closing) {
417417
return cb(new errors.BrokerNotAvailableError('Could not find the leader'), payloads[leader]);
418418
}
419419

420420
if (longpolling) {
421-
if (broker.waitting) continue;
422-
broker.waitting = true;
421+
if (broker.socket.waitting) continue;
422+
broker.socket.waitting = true;
423423
}
424424

425425
if (decoder.requireAcks == 0) {
@@ -579,29 +579,29 @@ Client.prototype.handleReceivedData = function (socket) {
579579
setImmediate(function () { this.handleReceivedData(socket);}.bind(this));
580580
};
581581

582-
Client.prototype.queueCallback = function (broker, id, data) {
583-
var brokerId = broker.socketId;
582+
Client.prototype.queueCallback = function (socket, id, data) {
583+
var socketId = socket.socketId;
584584
var queue;
585585

586-
if (this.cbqueue.hasOwnProperty(brokerId)) {
587-
queue = this.cbqueue[brokerId];
586+
if (this.cbqueue.hasOwnProperty(socketId)) {
587+
queue = this.cbqueue[socketId];
588588
}
589589
else {
590590
queue = {};
591-
this.cbqueue[brokerId] = queue;
591+
this.cbqueue[socketId] = queue;
592592
}
593593

594594
queue[id] = data;
595595
};
596596

597-
Client.prototype.unqueueCallback = function (broker, id) {
598-
var brokerId = broker.socketId;
597+
Client.prototype.unqueueCallback = function (socket, id) {
598+
var socketId = socket.socketId;
599599

600-
if (!this.cbqueue.hasOwnProperty(brokerId)) {
600+
if (!this.cbqueue.hasOwnProperty(socketId)) {
601601
return null;
602602
}
603603

604-
var queue = this.cbqueue[brokerId];
604+
var queue = this.cbqueue[socketId];
605605
if (!queue.hasOwnProperty(id)) {
606606
return null;
607607
}
@@ -611,21 +611,21 @@ Client.prototype.unqueueCallback = function (broker, id) {
611611
// cleanup socket queue
612612
delete queue[id];
613613
if (!Object.keys(queue).length) {
614-
delete this.cbqueue[brokerId];
614+
delete this.cbqueue[socketId];
615615
}
616616

617617
return result;
618618
};
619619

620-
Client.prototype.clearCallbackQueue = function (broker, error) {
621-
var brokerId = broker.socketId;
622-
var longpolling = broker.longpolling;
620+
Client.prototype.clearCallbackQueue = function (socket, error) {
621+
var socketId = socket.socketId;
622+
var longpolling = socket.longpolling;
623623

624-
if (!this.cbqueue.hasOwnProperty(brokerId)) {
624+
if (!this.cbqueue.hasOwnProperty(socketId)) {
625625
return;
626626
}
627627

628-
var queue = this.cbqueue[brokerId];
628+
var queue = this.cbqueue[socketId];
629629

630630
if (!longpolling) {
631631
Object.keys(queue).forEach(function (key) {
@@ -634,7 +634,7 @@ Client.prototype.clearCallbackQueue = function (broker, error) {
634634
cb(error);
635635
});
636636
}
637-
delete this.cbqueue[brokerId];
637+
delete this.cbqueue[socketId];
638638
};
639639

640640
module.exports = Client;

0 commit comments

Comments
 (0)