hotfix: clear the offline queue when once written
diff --git a/lib/nodejs/lib/thrift/connection.js b/lib/nodejs/lib/thrift/connection.js
index 9e5c063..72ecb69 100644
--- a/lib/nodejs/lib/thrift/connection.js
+++ b/lib/nodejs/lib/thrift/connection.js
@@ -74,10 +74,7 @@
this.framePos = 0;
this.frame = null;
self.initialize_retry_vars();
-
- self.offline_queue.forEach(function(data) {
- self.connection.write(data);
- });
+ self.flush_offline_queue();
self.emit("connect");
});
@@ -177,6 +174,18 @@
this.attempts = 0;
};
+Connection.prototype.flush_offline_queue = function () {
+ var self = this;
+ var offline_queue = this.offline_queue;
+
+ // Reset offline queue
+ this.offline_queue = [];
+ // Attempt to write queued items
+ offline_queue.forEach(function(data) {
+ self.write(data);
+ });
+};
+
Connection.prototype.write = function(data) {
if (!this.connected) {
this.offline_queue.push(data);
@@ -311,10 +320,7 @@
this.frame = null;
this.connected = true;
- self.offline_queue.forEach(function(data) {
- self.connection.write(data);
- });
-
+ self.flush_offline_queue();
this.connection.addListener("error", function(err) {
self.emit("error", err);
@@ -359,6 +365,18 @@
this.connection.end();
};
+StdIOConnection.prototype.flush_offline_queue = function () {
+ var self = this;
+ var offline_queue = this.offline_queue;
+
+ // Reset offline queue
+ this.offline_queue = [];
+ // Attempt to write queued items
+ offline_queue.forEach(function(data) {
+ self.write(data);
+ });
+};
+
StdIOConnection.prototype.write = function(data) {
if (!this.connected) {
this.offline_queue.push(data);