GeezerVison is showing github.com — http: set IncomingMessage.destroyed · nodejs/node@b634d4b
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_client.js +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -422,10 +422,12 @@ function socketCloseListener() { | 422 | 422 | req.emit('close'); | 423 | 423 | if (!res.aborted && res.readable) { | 424 | 424 | res.on('end', function() { | | 425 | + this.destroyed = true; | 425 | 426 | this.emit('close'); | 426 | 427 | }); | 427 | 428 | res.push(null); | 428 | 429 | } else { | | 430 | + res.destroyed = true; | 429 | 431 | res.emit('close'); | 430 | 432 | } | 431 | 433 | } else { | @@ -539,6 +541,7 @@ function socketOnData(d) { | 539 | 541 | socket.readableFlowing = null; | 540 | 542 |
| 541 | 543 | req.emit(eventName, res, socket, bodyHead); | | 544 | + req.destroyed = true; | 542 | 545 | req.emit('close'); | 543 | 546 | } else { | 544 | 547 | // Requested Upgrade or used CONNECT method, but have no handler. | @@ -710,6 +713,7 @@ function requestOnPrefinish() { | 710 | 713 | function emitFreeNT(req) { | 711 | 714 | req.emit('close'); | 712 | 715 | if (req.res) { | | 716 | + req.res.destroyed = true; | 713 | 717 | req.res.emit('close'); | 714 | 718 | } | 715 | 719 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_incoming.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -119,6 +119,8 @@ IncomingMessage.prototype._read = function _read(n) { | 119 | 119 | // any messages, before ever calling this. In that case, just skip | 120 | 120 | // it, since something else is destroying this connection anyway. | 121 | 121 | IncomingMessage.prototype.destroy = function destroy(error) { | | 122 | + // TODO(ronag): Implement in terms of _destroy | | 123 | + this.destroyed = true; | 122 | 124 | if (this.socket) | 123 | 125 | this.socket.destroy(error); | 124 | 126 | }; | |
Collapse file Copy file name to clipboardExpand all lines: lib/_http_server.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -205,7 +205,10 @@ function onServerResponseClose() { | 205 | 205 | // Ergo, we need to deal with stale 'close' events and handle the case | 206 | 206 | // where the ServerResponse object has already been deconstructed. | 207 | 207 | // Fortunately, that requires only a single if check. :-) | 208 | | - if (this._httpMessage) this._httpMessage.emit('close'); | | 208 | + if (this._httpMessage) { | | 209 | + this._httpMessage.destroyed = true; | | 210 | + this._httpMessage.emit('close'); | | 211 | + } | 209 | 212 | } | 210 | 213 |
| 211 | 214 | ServerResponse.prototype.assignSocket = function assignSocket(socket) { | @@ -534,6 +537,7 @@ function abortIncoming(incoming) { | 534 | 537 | while (incoming.length) { | 535 | 538 | const req = incoming.shift(); | 536 | 539 | req.aborted = true; | | 540 | + req.destroyed = true; | 537 | 541 | req.emit('aborted'); | 538 | 542 | req.emit('close'); | 539 | 543 | } | @@ -660,11 +664,13 @@ function clearIncoming(req) { | 660 | 664 | if (parser && parser.incoming === req) { | 661 | 665 | if (req.readableEnded) { | 662 | 666 | parser.incoming = null; | | 667 | + req.destroyed = true; | 663 | 668 | req.emit('close'); | 664 | 669 | } else { | 665 | 670 | req.on('end', clearIncoming); | 666 | 671 | } | 667 | 672 | } else { | | 673 | + req.destroyed = true; | 668 | 674 | req.emit('close'); | 669 | 675 | } | 670 | 676 | } | @@ -708,6 +714,7 @@ function resOnFinish(req, res, socket, state, server) { | 708 | 714 | } | 709 | 715 |
| 710 | 716 | function emitCloseNT(self) { | | 717 | + self.destroyed = true; | 711 | 718 | self.emit('close'); | 712 | 719 | } | 713 | 720 |
| |
Collapse file Copy file name to clipboard +41Lines changed: 41 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +'use strict'; | | 2 | +const common = require('../common'); | | 3 | +const assert = require('assert'); | | 4 | +const http = require('http'); | | 5 | + | | 6 | +{ | | 7 | + const server = http.createServer(common.mustCall((req, res) => { | | 8 | + res.end('asd'); | | 9 | + })); | | 10 | + | | 11 | + server.listen(0, common.mustCall(() => { | | 12 | + http.get({ | | 13 | + port: server.address().port | | 14 | + }, common.mustCall((res) => { | | 15 | + assert.strictEqual(res.destroyed, false); | | 16 | + res.destroy(); | | 17 | + assert.strictEqual(res.destroyed, true); | | 18 | + res.on('close', common.mustCall(() => { | | 19 | + server.close(); | | 20 | + })); | | 21 | + })); | | 22 | + })); | | 23 | +} | | 24 | + | | 25 | +{ | | 26 | + const server = http.createServer(common.mustCall((req, res) => { | | 27 | + res.end('asd'); | | 28 | + })); | | 29 | + | | 30 | + server.listen(0, common.mustCall(() => { | | 31 | + http.get({ | | 32 | + port: server.address().port | | 33 | + }, common.mustCall((res) => { | | 34 | + assert.strictEqual(res.destroyed, false); | | 35 | + res.on('close', common.mustCall(() => { | | 36 | + assert.strictEqual(res.destroyed, true); | | 37 | + server.close(); | | 38 | + })).resume(); | | 39 | + })); | | 40 | + })); | | 41 | +} |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-connect-req-res.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,7 +33,10 @@ server.listen(0, common.mustCall(function() { | 33 | 33 | path: 'example.com:443' | 34 | 34 | }, common.mustNotCall()); | 35 | 35 |
| 36 | | - req.on('close', common.mustCall()); | | 36 | + assert.strictEqual(req.destroyed, false); | | 37 | + req.on('close', common.mustCall(() => { | | 38 | + assert.strictEqual(req.destroyed, true); | | 39 | + })); | 37 | 40 |
| 38 | 41 | req.on('connect', common.mustCall(function(res, socket, firstBodyChunk) { | 39 | 42 | console.error('Client got CONNECT request'); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-connect.js +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,7 +62,10 @@ server.listen(0, common.mustCall(() => { | 62 | 62 | assert.strictEqual(socket._httpMessage, req); | 63 | 63 | })); | 64 | 64 |
| 65 | | - req.on('close', common.mustCall()); | | 65 | + assert.strictEqual(req.destroyed, false); | | 66 | + req.on('close', common.mustCall(() => { | | 67 | + assert.strictEqual(req.destroyed, true); | | 68 | + })); | 66 | 69 |
| 67 | 70 | req.on('connect', common.mustCall((res, socket, firstBodyChunk) => { | 68 | 71 | // Make sure this request got removed from the pool. | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-pause-resume-one-end.js +8-1Lines changed: 8 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 | const common = require('../common'); | 24 | 24 | const http = require('http'); | | 25 | +const assert = require('assert'); | 25 | 26 |
| 26 | 27 | const server = http.Server(function(req, res) { | 27 | 28 | res.writeHead(200, { 'Content-Type': 'text/plain' }); | @@ -43,6 +44,12 @@ server.listen(0, common.mustCall(function() { | 43 | 44 | }); | 44 | 45 | })); | 45 | 46 |
| 46 | | - res.on('end', common.mustCall()); | | 47 | + res.on('end', common.mustCall(() => { | | 48 | + assert.strictEqual(res.destroyed, false); | | 49 | + })); | | 50 | + assert.strictEqual(res.destroyed, false); | | 51 | + res.on('close', common.mustCall(() => { | | 52 | + assert.strictEqual(res.destroyed, true); | | 53 | + })); | 47 | 54 | })); | 48 | 55 | })); |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-req-res-close.js +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -8,13 +8,25 @@ const server = http.Server(common.mustCall((req, res) => { | 8 | 8 | let resClosed = false; | 9 | 9 |
| 10 | 10 | res.end(); | | 11 | + let resFinished = false; | 11 | 12 | res.on('finish', common.mustCall(() => { | | 13 | + resFinished = true; | | 14 | + assert.strictEqual(resClosed, false); | | 15 | + assert.strictEqual(res.destroyed, false); | 12 | 16 | assert.strictEqual(resClosed, false); | 13 | 17 | })); | | 18 | + assert.strictEqual(req.destroyed, false); | 14 | 19 | res.on('close', common.mustCall(() => { | 15 | 20 | resClosed = true; | | 21 | + assert.strictEqual(resFinished, true); | | 22 | + assert.strictEqual(res.destroyed, true); | | 23 | + })); | | 24 | + assert.strictEqual(req.destroyed, false); | | 25 | + req.on('end', common.mustCall(() => { | | 26 | + assert.strictEqual(req.destroyed, false); | 16 | 27 | })); | 17 | 28 | req.on('close', common.mustCall(() => { | | 29 | + assert.strictEqual(req.destroyed, true); | 18 | 30 | assert.strictEqual(req._readableState.ended, true); | 19 | 31 | })); | 20 | 32 | res.socket.on('close', () => server.close()); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-response-close.js +8Lines changed: 8 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 22 | 22 | 'use strict'; | 23 | 23 | const common = require('../common'); | 24 | 24 | const http = require('http'); | | 25 | +const assert = require('assert'); | 25 | 26 |
| 26 | 27 | { | 27 | 28 | const server = http.createServer( | @@ -39,7 +40,9 @@ const http = require('http'); | 39 | 40 | res.on('data', common.mustCall(() => { | 40 | 41 | res.destroy(); | 41 | 42 | })); | | 43 | + assert.strictEqual(res.destroyed, false); | 42 | 44 | res.on('close', common.mustCall(() => { | | 45 | + assert.strictEqual(res.destroyed, true); | 43 | 46 | server.close(); | 44 | 47 | })); | 45 | 48 | }) | @@ -61,7 +64,12 @@ const http = require('http'); | 61 | 64 | http.get( | 62 | 65 | { port: server.address().port }, | 63 | 66 | common.mustCall((res) => { | | 67 | + assert.strictEqual(res.destroyed, false); | | 68 | + res.on('end', common.mustCall(() => { | | 69 | + assert.strictEqual(res.destroyed, false); | | 70 | + })); | 64 | 71 | res.on('close', common.mustCall(() => { | | 72 | + assert.strictEqual(res.destroyed, true); | 65 | 73 | server.close(); | 66 | 74 | })); | 67 | 75 | res.resume(); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-http-server-stale-close.js +3Lines changed: 3 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | require('../common'); | 24 | 24 | const http = require('http'); | 25 | 25 | const fork = require('child_process').fork; | | 26 | +const assert = require('assert'); | 26 | 27 |
| 27 | 28 | if (process.env.NODE_TEST_FORK_PORT) { | 28 | 29 | const req = http.request({ | @@ -37,7 +38,9 @@ if (process.env.NODE_TEST_FORK_PORT) { | 37 | 38 | const server = http.createServer((req, res) => { | 38 | 39 | res.writeHead(200, { 'Content-Length': '42' }); | 39 | 40 | req.pipe(res); | | 41 | + assert.strictEqual(req.destroyed, false); | 40 | 42 | req.on('close', () => { | | 43 | + assert.strictEqual(req.destroyed, true); | 41 | 44 | server.close(); | 42 | 45 | res.end(); | 43 | 46 | }); | |
|