This is an automated email from the ASF dual-hosted git repository.
jking pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/thrift.git
The following commit(s) were added to refs/heads/master by this push:
new c035eca hotfix: clear the offline queue when once written
c035eca is described below
commit c035eca3c672511779440bd0779ce5bc93d5c327
Author: Henrik Tudborg <[email protected]>
AuthorDate: Mon Apr 18 20:20:10 2016 +0200
hotfix: clear the offline queue when once written
---
lib/nodejs/lib/thrift/connection.js | 34 ++++++++++++++++++++++++++--------
1 file changed, 26 insertions(+), 8 deletions(-)
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 @@ 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);