-
Notifications
You must be signed in to change notification settings - Fork 520
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
How to properly utilize keep alive to reuse connections? #941
Comments
After several hours of debugging this here is what we found. The code related to the forever setting invalidates the settings set by twilio-node/src/base/RequestClient.ts Lines 168 to 172 in 7519b2f
This code executes before axios/http.Agent has a chance to set the This means the http.Agent keep alive settings end up being ignored. The correct course of action here is probably to remove the else block and let the underlying client (axios) handle the connection header when it is not being explicitly set by the |
A workaround that we found to solve this issue was to extend the const twilio = require("twilio");
class MyReqClient extends twilio.RequestClient {
request(opts) {
return super.request({
...opts,
forever: true,
});
}
}
// ...
const client = new twilio.Twilio(accountId, accountSecret, {
logLevel: "info",
httpClient: new MyReqClient({
autoRetry: true,
maxRetries: 5,
}),
}); Not the best solution, but it solves the issue while we wait for a proper fix. |
Looks like this PR will address these issues. |
Issue Summary
It's unclear from the documentation how to properly re-use connections. There are only sporadic comments and it seems there are multiple settings
keepAlive
withkeepAliveMSecs
and/orforever
.We have created a Twilio instance with the following but our APM is still showing every request opening a new tcp connection and querying DNS so the connections are not being reused.
ClientOpts
has no way to pass inkeepAlive
settings so we have to instead pass in the httpClient.We have also found the forever option in
RequestOptions
.Does this end up overriding the RequestClients keepAlive settings? It's also not clear where this can be passed in?
Looking for an example of how to properly pool connections.
Technical details:
The text was updated successfully, but these errors were encountered: