@@ -374,7 +374,9 @@ function socketCloseListener() {
374374 // receive a response. The error needs to
375375 // fire on the request.
376376 req . socket . _hadError = true ;
377- req . emit ( 'error' , connResetException ( 'socket hang up' ) ) ;
377+ if ( ! req . aborted ) {
378+ req . emit ( 'error' , connResetException ( 'socket hang up' ) ) ;
379+ }
378380 }
379381 req . emit ( 'close' ) ;
380382 }
@@ -400,7 +402,9 @@ function socketErrorListener(err) {
400402 // For Safety. Some additional errors might fire later on
401403 // and we need to make sure we don't double-fire the error event.
402404 req . socket . _hadError = true ;
403- req . emit ( 'error' , err ) ;
405+ if ( ! req . aborted ) {
406+ req . emit ( 'error' , err ) ;
407+ }
404408 }
405409
406410 // Handle any pending data
@@ -434,7 +438,9 @@ function socketOnEnd() {
434438 // If we don't have a response then we know that the socket
435439 // ended prematurely and we need to emit an error on the request.
436440 req . socket . _hadError = true ;
437- req . emit ( 'error' , connResetException ( 'socket hang up' ) ) ;
441+ if ( ! req . aborted ) {
442+ req . emit ( 'error' , connResetException ( 'socket hang up' ) ) ;
443+ }
438444 }
439445 if ( parser ) {
440446 parser . finish ( ) ;
@@ -457,7 +463,9 @@ function socketOnData(d) {
457463 freeParser ( parser , req , socket ) ;
458464 socket . destroy ( ) ;
459465 req . socket . _hadError = true ;
460- req . emit ( 'error' , ret ) ;
466+ if ( ! req . aborted ) {
467+ req . emit ( 'error' , ret ) ;
468+ }
461469 } else if ( parser . incoming && parser . incoming . upgrade ) {
462470 // Upgrade (if status code 101) or CONNECT
463471 var bytesParsed = ret ;
0 commit comments