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

Connections cleanup after timeout #60

Open
gnostis opened this issue Sep 16, 2019 · 0 comments
Open

Connections cleanup after timeout #60

gnostis opened this issue Sep 16, 2019 · 0 comments

Comments

@gnostis
Copy link

gnostis commented Sep 16, 2019

Just tested the behavior of timeout and memory after running below function 100 times cycled.
Url has 3 minutes delay in response and timeout happens immideately. I thought that appropriate connection will be closed after promise is rejected with TimeoutError and everything will be cleaned. But memory grows. I tried disconnectAll after catching timeout and there is slightly better memory usage after cycle in case of that. All connections stay alive until 3 minutes passed. If we do nearly the same but using AbortController signal cancelling fetches, memory stays constant and there is no any leaks and pending connections.

So the main question is how to clean up connection immideately after timeout?
Under heavy load and under certain conditions, a memory leak will occur.
Experimented to abort after timeouts but no result.

async function fetchTest() {
  try {
      let newCtx = context(); 
      var response = await newCtx.fetch('https://httpstat.us/200?sleep=180000',{timeout: 10});
  }
  catch (e) {
    console.log(e.constructor.name);
    newCtx.disconnectAll();  //consumes less memory with disconnecting after timeot
    return {error: e.constructor.name}; 
  } 
  return { body: await response.text() };
}
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

1 participant