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

Error [ERR_HTTP2_INVALID_SESSION]: The session has been destroyed #88

Open
asppsa opened this issue Mar 11, 2020 · 2 comments
Open

Error [ERR_HTTP2_INVALID_SESSION]: The session has been destroyed #88

asppsa opened this issue Mar 11, 2020 · 2 comments

Comments

@asppsa
Copy link

asppsa commented Mar 11, 2020

I've got a long-running node application that occasionally makes a flurry of requests to an AWS server. If the application has been sitting dormant for a few minutes, and then makes a request, the application crashes with an error:

Error [ERR_HTTP2_INVALID_SESSION]: The session has been destroyed
    at ClientHttp2Session.request (internal/http2/core.js:1560:13)
    at doFetch (/Users/apharo/Blake/content-build-tools/node_modules/fetch-h2/dist/lib/fetch-http2.js:49:32)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)

Using fetch-h2 2.4.0 with NodeJS v12.15.0. At this stage I'm not sure if the crash is avoidable or not - I'll see if I can create a simple repro of the issue.

@stefan-guggisberg
Copy link
Contributor

We're experiencing the same issue. We're using fetch-h2 in long-running code, sending frequent requests to some HTTP/2 backend (Azure Front Door for example).

I can reproduce the problem by sending the same request in an endless loop in certain intervals (e.g. every 5 seconds), something like

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

const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

const url = '<some http/2 server url>';
 
const main = async () => {
  let cnt = 1;
  let errCnt = 0;
  const MAX_ERRORS = 10;
  while (true) {
    console.log(`iteration #${cnt++}, ts: ${new Date().toISOString().slice(11, 23)} UTC`);
    try {
      const resp = await fetch(url);
      console.log(`status: ${resp.status}, httpVersion: ${resp.httpVersion}`);
      const data = await resp.text();
      console.log(`response body: ${data}\n\n`);
    } catch (err) {
      errCnt++;
      console.log(`caught error #${errCnt}: ${err}`);
      console.error(err);
      if (errCnt > MAX_ERRORS) {
        console.log('rethrowing ...');
        throw err;
      }
    }
    await sleep(5000);
  }
};

main().then(() => {
  console.log('cleaning up...');
  return disconnectAll();
}).catch((err) => {
  console.log(`caught error: ${err}`);
  console.error(err);
});

After some time (usually a couple of hours) we're seeing first an ECONNRESET error followed by ERR_HTTP2_INVALID_SESSION errors which it doesn't recover from:

...
iteration #12035, ts: 13:18:04.453 UTC
status: 200, httpVersion: 2
iteration #12036, ts: 13:18:10.546 UTC
caught error #1: Error: read ECONNRESET
Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:205:27) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read'
}
iteration #12037, ts: 13:18:15.574 UTC
caught error #2: Error [ERR_HTTP2_INVALID_SESSION]: The session has been destroyed
Error [ERR_HTTP2_INVALID_SESSION]: The session has been destroyed
    at ClientHttp2Session.request (internal/http2/core.js:1587:13)
    at doFetch (/projects/fetch-test/node_modules/fetch-h2/dist/lib/fetch-http2.js:51:32) {
  code: 'ERR_HTTP2_INVALID_SESSION'
}

The problem seems to be that the cached http2 session in fetch-h2 is not discarded once it errors and subsequent requests to the same origin will result in ERR_HTTP2_INVALID_SESSION errors.

@cool-firer
Copy link

is this problem solved? I met the same error.

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