GeezerVison is showing github.com — http: don't emit 'readable' after 'close' · nodejs/node@3b02042
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: lib/_http_server.js +4-2Lines changed: 4 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -660,9 +660,12 @@ function clearIncoming(req) { | 660 | 660 | if (parser && parser.incoming === req) { | 661 | 661 | if (req.readableEnded) { | 662 | 662 | parser.incoming = null; | | 663 | + req.emit('close'); | 663 | 664 | } else { | 664 | 665 | req.on('end', clearIncoming); | 665 | 666 | } | | 667 | + } else { | | 668 | + req.emit('close'); | 666 | 669 | } | 667 | 670 | } | 668 | 671 |
| @@ -673,7 +676,6 @@ function resOnFinish(req, res, socket, state, server) { | 673 | 676 | assert(state.incoming.length === 0 || state.incoming[0] === req); | 674 | 677 |
| 675 | 678 | state.incoming.shift(); | 676 | | - clearIncoming(req); | 677 | 679 |
| 678 | 680 | // If the user never called req.read(), and didn't pipe() or | 679 | 681 | // .resume() or .on('data'), then we call req._dump() so that the | @@ -682,7 +684,7 @@ function resOnFinish(req, res, socket, state, server) { | 682 | 684 | req._dump(); | 683 | 685 |
| 684 | 686 | res.detachSocket(socket); | 685 | | - req.emit('close'); | | 687 | + clearIncoming(req); | 686 | 688 | process.nextTick(emitCloseNT, res); | 687 | 689 |
| 688 | 690 | if (res._last) { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-async-hooks-http-parser-destroy.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | 'use strict'; | 2 | | -require('../common'); | | 2 | +const common = require('../common'); | 3 | 3 | const assert = require('assert'); | 4 | 4 | const async_hooks = require('async_hooks'); | 5 | 5 | const http = require('http'); | @@ -45,6 +45,9 @@ async_hooks.createHook({ | 45 | 45 | }).enable(); | 46 | 46 |
| 47 | 47 | const server = http.createServer((req, res) => { | | 48 | + req.on('close', common.mustCall(() => { | | 49 | + req.on('readable', common.mustNotCall()); | | 50 | + })); | 48 | 51 | res.end('Hello'); | 49 | 52 | }); | 50 | 53 |
| |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-no-read-no-dump.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -11,6 +11,10 @@ const server = http.createServer((req, res) => { | 11 | 11 | res.writeHead(200); | 12 | 12 | res.flushHeaders(); | 13 | 13 |
| | 14 | + req.on('close', common.mustCall(() => { | | 15 | + req.on('end', common.mustNotCall()); | | 16 | + })); | | 17 | + | 14 | 18 | req.connection.on('pause', () => { | 15 | 19 | res.end(); | 16 | 20 | onPause(); | |
|