Skip to content

Commit

Permalink
Fixed a couple of bugs with disconnection on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
baudehlo committed Apr 11, 2011
1 parent e3d9648 commit 0cceec1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions connection.js
Expand Up @@ -18,15 +18,13 @@ function setupClient(self) {

self.client.on('error', function (err) {
if (!self.disconnected) {
logger.logwarn("client closed with err: " + err);
self.disconnect();
self.fail("client closed with err: " + err);
}
});

self.client.on('timeout', function () {
if (!self.disconnected) {
logger.logerror("client (" + self.client.fd + ") timed out");
self.disconnect();
self.fail("client (" + self.client.fd + ") timed out");
}
});

Expand Down Expand Up @@ -93,7 +91,7 @@ Connection.prototype.process_line = function (line) {
logger.logerror(method + " failed: " + err);
}
this.respond(500, "Internal Server Error");
this.disconnect;
this.disconnect();
}
}
else {
Expand Down Expand Up @@ -178,6 +176,12 @@ Connection.prototype.respond = function(code, messages) {
this.state = 'cmd';
};

Connection.prototype.fail = function (err) {
logger.logwarn(err);
this.hooks_to_run = [];
this.disconnect();
}

Connection.prototype.disconnect = function() {
plugins.run_hooks('disconnect', this);
};
Expand Down

0 comments on commit 0cceec1

Please sign in to comment.