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

fix(node): reuse http agent across client #1216

Merged
merged 1 commit into from
Oct 19, 2020

Conversation

bodinsamuel
Copy link
Contributor

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
@@ -12,14 +12,17 @@ export type NodeHttpRequesterOptions = {
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
Contributor 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.

None yet

2 participants