File tree 2 files changed +18
-3
lines changed
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -822,12 +822,27 @@ const requestHeaderFieldsTooLargeResponse = Buffer.from(
822
822
`HTTP/1.1 431 ${ STATUS_CODES [ 431 ] } \r\n` +
823
823
'Connection: close\r\n\r\n' , 'ascii' ,
824
824
) ;
825
+
826
+ function warnUnclosedSocket ( ) {
827
+ if ( warnUnclosedSocket . emitted ) {
828
+ return ;
829
+ }
830
+
831
+ warnUnclosedSocket . emitted = true ;
832
+ process . emitWarning (
833
+ 'An error event has already been emitted on the request. ' +
834
+ 'Please use the destroy method on the socket while handling a clientError event.' ,
835
+ ) ;
836
+ }
837
+
825
838
function socketOnError ( e ) {
826
839
// Ignore further errors
827
840
this . removeListener ( 'error' , socketOnError ) ;
828
841
829
842
if ( this . listenerCount ( 'error' , noop ) === 0 ) {
830
843
this . on ( 'error' , noop ) ;
844
+ } else {
845
+ warnUnclosedSocket ( ) ;
831
846
}
832
847
833
848
if ( ! this . server . emit ( 'clientError' , e , this ) ) {
Original file line number Diff line number Diff line change
1
+ // Flags: --no-warnings
2
+
1
3
'use strict' ;
2
4
3
5
const common = require ( '../common' ) ;
@@ -15,8 +17,7 @@ const net = require('net');
15
17
{
16
18
let i = 0 ;
17
19
let socket ;
18
- const mustNotCall = common . mustNotCall . bind ( null ) ;
19
- process . on ( 'warning' , mustNotCall ) ;
20
+ process . on ( 'warning' , common . mustCall ( ) ) ;
20
21
21
22
const server = http . createServer ( common . mustNotCall ( ) ) ;
22
23
@@ -41,7 +42,6 @@ const net = require('net');
41
42
42
43
socket . on ( 'close' , ( ) => {
43
44
server . close ( ) ;
44
- process . removeListener ( 'warning' , mustNotCall ) ;
45
45
} ) ;
46
46
} ) ;
47
47
}
You can’t perform that action at this time.
0 commit comments