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

feat: add keep alive support #1226

Closed
wants to merge 3 commits into from

Conversation

khshah6
Copy link

@khshah6 khshah6 commented Dec 4, 2020

Resolves: #950

Description
This fix enables consumers to reuse connections by supporting keep-alive.

When keepAlive is set to true, SendGrid will use forever-agent (HTTP Agent that keeps socket connections alive between keep-alive requests).

This has been tested in a simple node request. End users do not have to provide any additional information when calling SendGrid for a client or to send mail and as such has no breaking change.

Linked issue includes examples of similar changes made in Stripe and Twilio apis.

Checklist

  • I acknowledge that all my contributions will be made under the project's license
  • I have made a material change to the repo (functionality, testing, spelling, grammar)
  • I have read the Contribution Guidelines and my PR follows them
  • I have titled the PR appropriately
  • I have updated my branch with the main branch
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation about the functionality in the appropriate .md file
  • I have added inline documentation to the code I modified

If you have questions, please file a support ticket, or create a GitHub Issue in this repository.

@thinkingserious thinkingserious added the status: code review request requesting a community code review or review from Twilio label Dec 4, 2020
*/
setKeepAlive(keepAlive) {
if (keepAlive === false) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

What about turning off keep alive? If this just returns, you can never "unset" it.

Copy link
Author

Choose a reason for hiding this comment

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

keepAlive is already false by default, its an opt-in feature

return;
}

this.client.setDefaultRequest('agent', new Agent({ 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.

I think the key needs to be httpsAgent, according to the documentation. This logic should be moved to the underlying Client with a separate helper method that we can call from here, similar to calling this.client.setApiKey from setApiKey.

Copy link
Author

Choose a reason for hiding this comment

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

sure, good call out

@JenniferMah
Copy link
Contributor

Closing until PR feedback is addressed.

@JenniferMah JenniferMah closed this Jan 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: code review request requesting a community code review or review from Twilio
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add keep-alive support
4 participants