Navigation Menu

Skip to content

Commit

Permalink
Return 503 error when connection to an engine node is closed
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 8, 2015
1 parent 9039ce3 commit 80f13b5
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/droonga-protocol/connection.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 80f13b5

Please sign in to comment.