Skip to content

Commit

Permalink
hotfix: clear the offline queue when once written
Browse files Browse the repository at this point in the history
  • Loading branch information
tudborg authored and razvanz committed Apr 5, 2019
1 parent c9b1e29 commit 7aa5d99
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions lib/nodejs/lib/thrift/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7aa5d99

Please sign in to comment.