-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: fix no dumping after
maybeReadMore
When `maybeReadMore` kicks in on a first bytes of incoming data, the `req.read(0)` will be invoked and the `req._consuming` will be set to `true`. This seemingly harmless property leads to a dire consequences: the server won't call `req._dump()` and the whole HTTP/1.1 pipeline will hang (single connection). PR-URL: #7211 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const http = require('http'); | ||
|
||
let onPause = null; | ||
|
||
const server = http.createServer((req, res) => { | ||
if (req.method === 'GET') | ||
return res.end(); | ||
|
||
res.writeHead(200); | ||
res.flushHeaders(); | ||
|
||
req.connection.on('pause', () => { | ||
res.end(); | ||
onPause(); | ||
}); | ||
}).listen(common.PORT, common.mustCall(() => { | ||
const agent = new http.Agent({ | ||
maxSockets: 1, | ||
keepAlive: true | ||
}); | ||
|
||
const post = http.request({ | ||
agent: agent, | ||
method: 'POST', | ||
port: common.PORT, | ||
}, common.mustCall((res) => { | ||
res.resume(); | ||
|
||
post.write(Buffer.alloc(16 * 1024).fill('X')); | ||
onPause = () => { | ||
post.end('something'); | ||
}; | ||
})); | ||
|
||
/* What happens here is that the server `end`s the response before we send | ||
* `something`, and the client thought that this is a green light for sending | ||
* next GET request | ||
*/ | ||
post.write('initial'); | ||
|
||
http.request({ | ||
agent: agent, | ||
method: 'GET', | ||
port: common.PORT, | ||
}, common.mustCall((res) => { | ||
server.close(); | ||
res.connection.end(); | ||
})).end(); | ||
})); |