Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Maximum call stack size exceeded #93

Open
stefan-guggisberg opened this issue Mar 19, 2020 · 3 comments
Open

RangeError: Maximum call stack size exceeded #93

stefan-guggisberg opened this issue Mar 19, 2020 · 3 comments

Comments

@stefan-guggisberg
Copy link
Contributor

Running many (e.g. 1000) parallel requests to the same http2 origin causes:

RangeError: Maximum call stack size exceeded
(node:96007) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
    at countWorking (/tmp/test/node_modules/already/dist/index.js:468:26)
    at freeSlots (/tmp/test/node_modules/already/dist/index.js:474:42)
    at shouldRetry (/tmp/test/node_modules/already/dist/index.js:497:26)
    at /tmp/test/node_modules/fetch-h2/dist/lib/context.js:196:72
    at /tmp/test/node_modules/already/dist/index.js:530:30
    at Try (/tmp/test/node_modules/already/dist/index.js:336:12)
    at runner (/tmp/test/node_modules/already/dist/index.js:530:20)
    at Object.resume (/tmp/test/node_modules/already/dist/index.js:514:34)
    at /tmp/test/node_modules/already/dist/index.js:482:18
    at Array.forEach (<anonymous>)

To reproduce:

Run node test.js 1000

test.js

const { fetch } = require('fetch-h2');

var args = process.argv.slice(2);
const N = args.length && !isNaN(parseInt(args[0])) ? parseInt(args[0]) : 100;

console.log(`running ${N} paralled requests...`)

const TEST_URL = 'https://httpbin.org/bytes/'; // HTTP2

(async function () {
  // generete array of 'randomized' urls
  const urls = Array.from({ length: N }, () => Math.floor(Math.random() * N)).map((num) => `${TEST_URL}${num}`);

  const ts0 = Date.now();

  // send requests
  const responses = await Promise.all(urls.map((url) => fetch(url)));

  // read bodies
  await Promise.all(responses.map((resp) => resp.arrayBuffer()));

  const ok = responses.filter((res) => res.ok);
  if (ok.length !== N) {
    console.log(`failed requests: ${N - ok.length}`);
  }

  const ts1 = Date.now();

  console.log(`Elapsed time: ${ts1 - ts0} ms`);
}());
@duongvanba
Copy link

Are there any solution to fix this ?

@0xmaayan
Copy link

same issue here! any known solution..?

@stefan-guggisberg
Copy link
Contributor Author

@0xmaayan Have you tried https://github.com/adobe/fetch ?

import { fetch, reset } from '@adobe/fetch';

const main = async () => {
  const args = process.argv.slice(2);
  const N = args.length && !isNaN(parseInt(args[0])) ? parseInt(args[0]) : 100;

  console.log(`running ${N} paralled requests...`)

  const TEST_URL = 'https://httpbin.org/bytes/'; // HTTP2
  // generete array of 'randomized' urls
  const urls = Array.from({ length: N }, () => Math.floor(Math.random() * N)).map((num) => `${TEST_URL}${num}`);

  const ts0 = Date.now();

  // send requests
  const responses = await Promise.all(urls.map((url) => fetch(url)));

  // read bodies
  await Promise.all(responses.map((resp) => resp.arrayBuffer()));

  const ok = responses.filter((res) => res.ok);
  if (ok.length !== N) {
    console.log(`failed requests: ${N - ok.length}`);
  }

  const ts1 = Date.now();

  console.log(`Elapsed time: ${ts1 - ts0} ms`);
}

main()
  .catch(console.error)
  .finally(reset);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants