Skip to content

Commit

Permalink
Improved error handling; drop connections and log warning.
Browse files Browse the repository at this point in the history
Previously, certain error cases could leave the connection hanging.
  • Loading branch information
rohanpm committed Jun 17, 2012
1 parent 75a5661 commit e6ab127
Showing 1 changed file with 41 additions and 7 deletions.
48 changes: 41 additions & 7 deletions src/gitproxy.js
Expand Up @@ -762,7 +762,7 @@ function gitProxyStateObject(fire) {
'api.dumpInfo': _.bind(dumpInfo, undefined, 'connecting to server'),
'conn.startUploadPack.err': function (ex) {
conn.fatalError('fatal error while connecting to server: ' + ex);
return '@error';
return ['@error', 'while connecting to server: ' + ex];
},
'conn.startUploadPack.done': function (stream) {
return ['ReadingServerPreamble', stream];
Expand Down Expand Up @@ -792,7 +792,10 @@ function gitProxyStateObject(fire) {
'clientStream.message': function (m) {
fire.conn.readClientWant(m);
},
'conn.readClientWant.done': 'WritingServerWant'
'conn.readClientWant.done': 'WritingServerWant',
'conn.readClientWant.err': function (ex) {
return ['@error', 'while reading client want: ' + ex];
}
}
},

Expand Down Expand Up @@ -981,9 +984,35 @@ function gitProxyStateObject(fire) {
'api.dumpInfo': _.bind(dumpInfo, undefined, '(finished)'),
'clientStream.close': '@ignore',
'exit': function () {
return ['@exit', cache_stat];
return ['@exit', undefined, cache_stat];
}
}
},

'@error': {
entry: function (error) {
if (error == undefined) {
error = 'unknown error';
}

warn( 'dropping connection: ' + error );

try {
conn.client.stream.destroy( );
} catch (e1) {}

try {
conn.server.stream.destroy( );
} catch (e2) {}

return ['@exit', error];
},

actions: {
'clientStream': '@ignore',
'serverStream': '@ignore',
'api.dumpInfo': _.bind(dumpInfo, undefined, 'terminating due to error')
}
}

};
Expand Down Expand Up @@ -1042,18 +1071,23 @@ GitProxy.prototype.constructor = GitProxy;
GitProxy.prototype.handleConnect = function (c) {
var sm = this.factory.spawn(c);
this.recordConnectionInProgress();
sm.on('error', _.bind(this.recordConnectionComplete, this, REASON_ERROR));
sm.on('exit', _.bind(this.recordConnectionComplete, this, REASON_EXIT));
sm.on('exit', _.bind(this.recordConnectionComplete, this));
sm.on('error', function (error) {
mylog.trace(0, 'Error (likely bug): ' + error);
});
sm.on('warn', function (warning) {
mylog.trace(0, 'Warning (likely bug): ' + warning);
});
};

GitProxy.prototype.recordConnectionInProgress = function () {
++this.stats.in_progress;
};

GitProxy.prototype.recordConnectionComplete = function (reason, warmth) {
GitProxy.prototype.recordConnectionComplete = function (error, warmth) {
--this.stats.in_progress;
++this.stats.completed;
if (reason == REASON_ERROR) {
if (error != undefined) {
++this.stats.error;
return;
}
Expand Down

0 comments on commit e6ab127

Please sign in to comment.