-
Notifications
You must be signed in to change notification settings - Fork 539
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use FinalizationRegistry to cancel the body if response is collected (#…
…3199) * use FinalizationRegistry to cancel the body if response is collected Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * fixup Signed-off-by: Matteo Collina <hello@matteocollina.com> * Update lib/dispatcher/client-h2.js Co-authored-by: Aras Abbasi <aras.abbasi@googlemail.com> --------- Signed-off-by: Matteo Collina <hello@matteocollina.com> Co-authored-by: Aras Abbasi <aras.abbasi@googlemail.com>
- Loading branch information
Showing
4 changed files
with
98 additions
and
10 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
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,53 @@ | ||
'use strict' | ||
|
||
const { randomFillSync } = require('node:crypto') | ||
const { setTimeout: sleep } = require('timers/promises') | ||
const { test } = require('node:test') | ||
const { fetch, Agent, setGlobalDispatcher } = require('../..') | ||
const { createServer } = require('node:http') | ||
const { closeServerAsPromise } = require('../utils/node-http') | ||
|
||
const blob = randomFillSync(new Uint8Array(1024 * 512)) | ||
|
||
// Enable when/if FinalizationRegistry in Node.js 18 becomes stable again | ||
const isNode18 = process.version.startsWith('v18') | ||
|
||
test('does not need the body to be consumed to continue', { timeout: 180_000, skip: isNode18 }, async (t) => { | ||
const agent = new Agent({ | ||
keepAliveMaxTimeout: 10, | ||
keepAliveTimeoutThreshold: 10 | ||
}) | ||
setGlobalDispatcher(agent) | ||
const server = createServer((req, res) => { | ||
res.writeHead(200) | ||
res.end(blob) | ||
}) | ||
t.after(closeServerAsPromise(server)) | ||
|
||
await new Promise((resolve) => { | ||
server.listen(0, resolve) | ||
}) | ||
|
||
const url = new URL(`http://127.0.0.1:${server.address().port}`) | ||
|
||
const batch = 50 | ||
const delay = 0 | ||
let total = 0 | ||
while (total < 10000) { | ||
// eslint-disable-next-line no-undef | ||
gc(true) | ||
const array = new Array(batch) | ||
for (let i = 0; i < batch; i++) { | ||
array[i] = fetch(url).catch(() => {}) | ||
} | ||
await Promise.all(array) | ||
await sleep(delay) | ||
|
||
console.log( | ||
'RSS', | ||
(process.memoryUsage.rss() / 1024 / 1024) | 0, | ||
'MB after', | ||
(total += batch) + ' fetch() requests' | ||
) | ||
} | ||
}) |