-
Notifications
You must be signed in to change notification settings - Fork 779
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
Conversation
*/ | ||
setKeepAlive(keepAlive) { | ||
if (keepAlive === false) { | ||
return; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 })); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, good call out
Closing until PR feedback is addressed. |
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
If you have questions, please file a support ticket, or create a GitHub Issue in this repository.