Skip to content

Conversation

@bodinsamuel
Copy link

Similar to #1215

When you create multiple clients, wether by mistake or needed if you index to multiple app, http agents are recreated by default. That means they do not share the TCP pool and will race for TCP connection, even if they are the same.
If they do not share same domains, at least it still reduce the cost of maintaining multiple TCP pool.

Reusing the Agent allow to:

  • reuse TCP connections,
  • reduce the chance of exhausting TCP connections on the host,
  • reduce the CPU cost,
  • and also reduce chance of getting ENOTFOUND EAI_AGAIN (Those errors are the most common ones that triggers the infamous "Unreachable hosts")

@bodinsamuel bodinsamuel self-assigned this Oct 18, 2020
httpsAgent?: https.Agent;
};

const agentOptions = { keepAlive: true };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be done inline now, I think it makes more sense

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, it's just to be sure both agent are in sync, don't you think it's less error prone like that?

@Haroenv Haroenv merged commit f6e9e56 into master Oct 19, 2020
@Haroenv Haroenv deleted the fix/reuse-http-agent-across-cliebt branch October 19, 2020 15:00
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

Successfully merging this pull request may close these issues.

3 participants