File tree 3 files changed +48
-5
lines changed
3 files changed +48
-5
lines changed Original file line number Diff line number Diff line change @@ -318,7 +318,9 @@ ClientRequest.prototype.abort = function abort() {
318
318
319
319
// If we're aborting, we don't care about any more response data.
320
320
if ( this . res ) {
321
- this . res . _dump ( ) ;
321
+ // TODO(ronag): No more data events should occur after destroy.
322
+ this . res . removeAllListeners ( 'data' ) ;
323
+ this . res . destroy ( ) ;
322
324
}
323
325
324
326
// In the event that we don't have a socket, we will pop out of
@@ -365,11 +367,11 @@ function socketCloseListener() {
365
367
req . emit ( 'close' ) ;
366
368
if ( res . readable ) {
367
369
res . on ( 'end' , function ( ) {
368
- this . emit ( 'close' ) ;
370
+ res . destroy ( ) ;
369
371
} ) ;
370
372
res . push ( null ) ;
371
373
} else {
372
- res . emit ( 'close' ) ;
374
+ res . destroy ( ) ;
373
375
}
374
376
} else {
375
377
if ( ! req . socket . _hadError ) {
Original file line number Diff line number Diff line change @@ -109,9 +109,11 @@ IncomingMessage.prototype._read = function _read(n) {
109
109
// It's possible that the socket will be destroyed, and removed from
110
110
// any messages, before ever calling this. In that case, just skip
111
111
// it, since something else is destroying this connection anyway.
112
- IncomingMessage . prototype . destroy = function destroy ( error ) {
112
+ IncomingMessage . prototype . _destroy = function destroy ( err , cb ) {
113
113
if ( this . socket )
114
- this . socket . destroy ( error ) ;
114
+ this . socket . destroy ( err , cb ) ;
115
+ else
116
+ cb ( err ) ;
115
117
} ;
116
118
117
119
Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+
3
+ const common = require ( '../common' ) ;
4
+ const assert = require ( 'assert' ) ;
5
+ const http = require ( 'http' ) ;
6
+
7
+ {
8
+ const server = http . Server ( function ( req , res ) {
9
+ req . destroy ( ) ;
10
+ assert . strictEqual ( req . destroyed , true ) ;
11
+ } ) ;
12
+
13
+ server . listen ( 0 , function ( ) {
14
+ http . get ( {
15
+ port : this . address ( ) . port ,
16
+ } ) . on ( 'error' , common . mustCall ( ( ) => {
17
+ server . close ( ) ;
18
+ } ) ) ;
19
+ } ) ;
20
+ }
21
+
22
+ {
23
+ const server = http . Server ( function ( req , res ) {
24
+ req . destroy ( new Error ( 'kaboom' ) ) ;
25
+ req . destroy ( new Error ( 'kaboom2' ) ) ;
26
+ assert . strictEqual ( req . destroyed , true ) ;
27
+ req . on ( 'error' , common . mustCall ( ( err ) => {
28
+ assert . strictEqual ( err . message , 'kaboom' ) ;
29
+ } ) ) ;
30
+ } ) ;
31
+
32
+ server . listen ( 0 , function ( ) {
33
+ http . get ( {
34
+ port : this . address ( ) . port ,
35
+ } ) . on ( 'error' , common . mustCall ( ( ) => {
36
+ server . close ( ) ;
37
+ } ) ) ;
38
+ } ) ;
39
+ }
You can’t perform that action at this time.
0 commit comments