Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Fix #3231. Don't try to emit error on a null'ed req object
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 7, 2012
1 parent e02af94 commit b4fbf6d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/http.js
Expand Up @@ -1158,18 +1158,21 @@ ClientRequest.prototype.onSocket = function(socket) {
// Setup "drain" propogation.
httpSocketSetup(socket);

var errorListener = function(err) {
function errorListener(err) {
debug('HTTP SOCKET ERROR: ' + err.message + '\n' + err.stack);
req.emit('error', err);
// For Safety. Some additional errors might fire later on
// and we need to make sure we don't double-fire the error event.
req._hadError = true;
if (req) {
req.emit('error', err);
// For Safety. Some additional errors might fire later on
// and we need to make sure we don't double-fire the error event.
req._hadError = true;
}
if (parser) {
parser.finish();
freeParser(parser, req);
}
socket.destroy();
}

socket.on('error', errorListener);

socket.ondata = function(d, start, end) {
Expand Down

0 comments on commit b4fbf6d

Please sign in to comment.