| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e1e57a4 commit cc5c8e0
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -413,6 +413,8 @@ function socketCloseListener() { | |||
| 413 | 413 | // the `socketOnData`. | |
| 414 | 414 | const parser = socket.parser; | |
| 415 | 415 | const res = req.res; | |
| 416 | + | ||
| 417 | + req.destroyed = true; | ||
| 416 | 418 | if (res) { | |
| 417 | 419 | // Socket closed before we emitted 'end' below. | |
| 418 | 420 | if (!res.complete) { | |
@@ -667,7 +669,9 @@ function responseKeepAlive(req) { | |||
| 667 | 669 | // handlers have a chance to run. | |
| 668 | 670 | defaultTriggerAsyncIdScope(asyncId, process.nextTick, emitFreeNT, req); | |
| 669 | 671 | ||
| 672 | + req.destroyed = true; | ||
| 670 | 673 | if (req.res) { | |
| 674 | + req.res.destroyed = true; | ||
| 671 | 675 | // Detach socket from IncomingMessage to avoid destroying the freed | |
| 672 | 676 | // socket in IncomingMessage.destroy(). | |
| 673 | 677 | req.res.socket = null; | |
@@ -713,7 +717,6 @@ function requestOnPrefinish() { | |||
| 713 | 717 | function emitFreeNT(req) { | |
| 714 | 718 | req.emit('close'); | |
| 715 | 719 | if (req.res) { | |
| 716 | - req.res.destroyed = true; | ||
| 717 | 720 | req.res.emit('close'); | |
| 718 | 721 | } | |
| 719 | 722 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | + const assert = require('assert'); | ||
| 3 | 4 | const http = require('http'); | |
| 4 | 5 | ||
| 5 | 6 | const server = http.createServer(common.mustNotCall()); | |
@@ -16,6 +17,7 @@ server.listen(0, common.mustCall(() => { | |||
| 16 | 17 | .on('socket', common.mustNotCall()) | |
| 17 | 18 | .on('response', common.mustNotCall()) | |
| 18 | 19 | .on('close', common.mustCall(() => { | |
| 20 | + assert.strictEqual(req.destroyed, true); | ||
| 19 | 21 | server.close(); | |
| 20 | 22 | keepAliveAgent.destroy(); | |
| 21 | 23 | })) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | 'use strict'; | |
| 2 | 2 | const common = require('../common'); | |
| 3 | + const assert = require('assert'); | ||
| 3 | 4 | const http = require('http'); | |
| 4 | 5 | ||
| 5 | 6 | const server = http.createServer(common.mustCall((req, res) => { | |
@@ -18,6 +19,7 @@ server.listen(0, common.mustCall(() => { | |||
| 18 | 19 | .on('response', common.mustCall((res) => { | |
| 19 | 20 | res | |
| 20 | 21 | .on('close', common.mustCall(() => { | |
| 22 | + assert.strictEqual(req.destroyed, true); | ||
| 21 | 23 | server.close(); | |
| 22 | 24 | keepAliveAgent.destroy(); | |
| 23 | 25 | })) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -22,6 +22,7 @@ server.listen(0, common.mustCall(() => { | |||
| 22 | 22 | })); | |
| 23 | 23 | ||
| 24 | 24 | req.on('close', common.mustCall(() => { | |
| 25 | + assert.strictEqual(req.destroyed, true); | ||
| 25 | 26 | assert.strictEqual(errorEmitted, true); | |
| 26 | 27 | server.close(); | |
| 27 | 28 | })); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,8 @@ function makeRequest() { | |||
| 21 | 21 | const req = http.get({ | |
| 22 | 22 | port: server.address().port | |
| 23 | 23 | }); | |
| 24 | - req.on('close', () => | ||
| 25 | - server.close()); | ||
| 24 | + req.on('close', () => { | ||
| 25 | + assert.strictEqual(req.destroyed, true); | ||
| 26 | + server.close(); | ||
| 27 | + }); | ||
| 26 | 28 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,6 +38,7 @@ server.listen(0, mustCall(() => { | |||
| 38 | 38 | })); | |
| 39 | 39 | ||
| 40 | 40 | req.on('close', mustCall(() => { | |
| 41 | + strictEqual(req.destroyed, true); | ||
| 41 | 42 | server.close(); | |
| 42 | 43 | })); | |
| 43 | 44 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -21,6 +21,7 @@ | |||
| 21 | 21 | ||
| 22 | 22 | 'use strict'; | |
| 23 | 23 | const common = require('../common'); | |
| 24 | + const assert = require('assert'); | ||
| 24 | 25 | const http = require('http'); | |
| 25 | 26 | ||
| 26 | 27 | const options = { | |
@@ -38,7 +39,10 @@ server.listen(0, options.host, function() { | |||
| 38 | 39 | req.on('error', function() { | |
| 39 | 40 | // This space is intentionally left blank | |
| 40 | 41 | }); | |
| 41 | - req.on('close', common.mustCall(() => server.close())); | ||
| 42 | + req.on('close', common.mustCall(() => { | ||
| 43 | + assert.strictEqual(req.destroyed, true); | ||
| 44 | + server.close(); | ||
| 45 | + })); | ||
| 42 | 46 | ||
| 43 | 47 | req.setTimeout(1); | |
| 44 | 48 | req.on('timeout', common.mustCall(() => { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,10 @@ server.listen(0, options.host, function() { | |||
| 23 | 23 | req.on('error', function() { | |
| 24 | 24 | // This space is intentionally left blank | |
| 25 | 25 | }); | |
| 26 | - req.on('close', common.mustCall(() => server.close())); | ||
| 26 | + req.on('close', common.mustCall(() => { | ||
| 27 | + assert.strictEqual(req.destroyed, true); | ||
| 28 | + server.close(); | ||
| 29 | + })); | ||
| 27 | 30 | ||
| 28 | 31 | let timeout_events = 0; | |
| 29 | 32 | req.on('timeout', common.mustCall(() => timeout_events += 1)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,7 @@ server.listen(0, options.host, function() { | |||
| 41 | 41 | // This space intentionally left blank | |
| 42 | 42 | }); | |
| 43 | 43 | req.on('close', function() { | |
| 44 | + assert.strictEqual(req.destroyed, true); | ||
| 44 | 45 | server.close(); | |
| 45 | 46 | }); | |
| 46 | 47 | function destroy() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,36 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const assert = require('assert'); | ||
| 5 | + | ||
| 6 | + const http = require('http'); | ||
| 7 | + | ||
| 8 | + for (const method of ['abort', 'destroy']) { | ||
| 9 | + const server = http.createServer(common.mustCall((req, res) => { | ||
| 10 | + res.end(req.url); | ||
| 11 | + })); | ||
| 12 | + server.listen(0, common.mustCall(() => { | ||
| 13 | + const agent = http.Agent({ keepAlive: true }); | ||
| 14 | + | ||
| 15 | + const req = http | ||
| 16 | + .request({ | ||
| 17 | + port: server.address().port, | ||
| 18 | + agent | ||
| 19 | + }) | ||
| 20 | + .on('socket', common.mustCall((socket) => { | ||
| 21 | + socket.on('free', common.mustCall()); | ||
| 22 | + })) | ||
| 23 | + .on('response', common.mustCall((res) => { | ||
| 24 | + assert.strictEqual(req.destroyed, false); | ||
| 25 | + res.on('end', () => { | ||
| 26 | + assert.strictEqual(req.destroyed, true); | ||
| 27 | + req[method](); | ||
| 28 | + assert.strictEqual(req.socket.destroyed, false); | ||
| 29 | + agent.destroy(); | ||
| 30 | + server.close(); | ||
| 31 | + }).resume(); | ||
| 32 | + })) | ||
| 33 | + .end(); | ||
| 34 | + assert.strictEqual(req.destroyed, false); | ||
| 35 | + })); | ||
| 36 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments