diff options
author | Henrik Tudborg <henrik@tudb.org> | 2016-04-18 20:20:10 +0200 |
---|---|---|
committer | James E. King III <jking@apache.org> | 2019-05-14 14:26:48 -0400 |
commit | c035eca3c672511779440bd0779ce5bc93d5c327 (patch) | |
tree | 61fd0d545b1a50851da53588e0dd0b50de61321f /lib/nodejs | |
parent | 79c23377057f5bbb2d52097eb13073db2d69db8c (diff) | |
download | thrift-c035eca3c672511779440bd0779ce5bc93d5c327.tar.gz |
hotfix: clear the offline queue when once written
Diffstat (limited to 'lib/nodejs')
-rw-r--r-- | lib/nodejs/lib/thrift/connection.js | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/nodejs/lib/thrift/connection.js b/lib/nodejs/lib/thrift/connection.js index 9e5c063cf..72ecb6955 100644 --- a/lib/nodejs/lib/thrift/connection.js +++ b/lib/nodejs/lib/thrift/connection.js @@ -74,10 +74,7 @@ var Connection = exports.Connection = function(stream, options) { 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 @@ Connection.prototype.initialize_retry_vars = function () { 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 @@ var StdIOConnection = exports.StdIOConnection = function(command, options) { 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 @@ StdIOConnection.prototype.end = function() { 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); |