summaryrefslogtreecommitdiff
path: root/test/parallel/test-http-no-read-no-dump.js
diff options
context:
space:
mode:
authorFedor Indutny <fedor@indutny.com>2016-06-04 00:21:04 -0400
committerFedor Indutny <fedor@indutny.com>2016-06-15 12:50:19 -0400
commit357f904169c39bbc9c2d8558bbffce2337c83c1b (patch)
tree2cfa1fb382da4d251cb07dc142f0800bf928074c /test/parallel/test-http-no-read-no-dump.js
parent1a1ff77feb3ed003e71bcbd066deadcaf9a82652 (diff)
downloadnode-new-357f904169c39bbc9c2d8558bbffce2337c83c1b.tar.gz
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: https://github.com/nodejs/node/pull/7211 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Diffstat (limited to 'test/parallel/test-http-no-read-no-dump.js')
-rw-r--r--test/parallel/test-http-no-read-no-dump.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/parallel/test-http-no-read-no-dump.js b/test/parallel/test-http-no-read-no-dump.js
new file mode 100644
index 0000000000..c509146c0a
--- /dev/null
+++ b/test/parallel/test-http-no-read-no-dump.js
@@ -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();
+}));