File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -28,14 +28,17 @@ const http = require('http');
28
28
const server = http . createServer ( ) ;
29
29
let connections = 0 ;
30
30
31
+ function ontimeout ( ) {
32
+ throw new Error ( 'Unexpected timeout' ) ;
33
+ }
34
+
31
35
server . on ( 'request' , function ( req , res ) {
32
36
req . socket . setTimeout ( 1000 ) ;
33
- req . socket . on ( 'timeout' , function ( ) {
34
- throw new Error ( 'Unexpected timeout' ) ;
35
- } ) ;
37
+ req . socket . on ( 'timeout' , ontimeout ) ;
36
38
req . on ( 'end' , function ( ) {
37
39
connections -- ;
38
40
res . writeHead ( 200 ) ;
41
+ req . socket . off ( 'timeout' , ontimeout ) ;
39
42
res . end ( 'done\n' ) ;
40
43
if ( connections === 0 ) {
41
44
server . close ( ) ;
@@ -57,7 +60,8 @@ server.listen(0, function() {
57
60
58
61
function ping ( ) {
59
62
const nextPing = ( Math . random ( ) * 900 ) . toFixed ( ) ;
60
- if ( nextPing > 600 ) {
63
+ // Do not set too big to prevent req.socket from emitting timeout
64
+ if ( nextPing > 300 ) {
61
65
request . end ( ) ;
62
66
return ;
63
67
}
You can’t perform that action at this time.
0 commit comments