[Groonga-commit] droonga/express-droonga at 80f13b5 [master] Return 503 error when connection to an engine node is closed

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Apr 8 20:07:07 JST 2015


YUKI Hiroshi	2015-04-08 20:07:07 +0900 (Wed, 08 Apr 2015)

  New Revision: 80f13b560a27a5c6860b81fb2944a6a54611f794
  https://github.com/droonga/express-droonga/commit/80f13b560a27a5c6860b81fb2944a6a54611f794

  Message:
    Return 503 error when connection to an engine node is closed

  Modified files:
    lib/droonga-protocol/connection.js

  Modified: lib/droonga-protocol/connection.js (+14 -1)
===================================================================
--- lib/droonga-protocol/connection.js    2015-04-08 15:42:50 +0900 (84f678d)
+++ lib/droonga-protocol/connection.js    2015-04-08 20:07:07 +0900 (eba48ec)
@@ -29,6 +29,10 @@ var DEFAULT_RECEIVE_HOST_NAME =
       Connection.DEFAULT_RECEIVE_HOST_NAME =
         '127.0.0.1';
 
+var ERROR_SERVICE_UNAVAILABLE =
+      Connection.ERROR_SERVICE_UNAVAILABLE =
+        503;
+
 var ERROR_GATEWAY_TIMEOUT =
       Connection.ERROR_GATEWAY_TIMEOUT =
         504;
@@ -246,7 +250,8 @@ Connection.prototype.emitMessage = function(type, body, callback, options) {
     }).bind(this), options.timeout);
   }
   this._sendingMessages[id] = {
-    type: type
+    type: type,
+    callback: callback
   };
   this._sender.emit('message', envelope, options.emittedCallback);
   return envelope;
@@ -276,6 +281,14 @@ Connection.prototype._sendPendingMessages = function() {
 Connection.prototype.close = function() {
   this.removeAllListeners();
 
+  Object.keys(this._sendingMessages).forEach(function(id) {
+    var message = this._sendingMessages[id];
+    var callback = message.callback;
+    if (typeof callback == 'function')
+      callback(ERROR_SERVICE_UNAVAILABLE, null);
+  }, this);
+  this._sendingMessages = {};
+
   if (this._sender && typeof this._sender.end == 'function') {
     try {
       this._sender.end();
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index