-
Notifications
You must be signed in to change notification settings - Fork 587
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-http-handler): call socket.setKeepAlive if enabled in http(s)Agent #4561
Conversation
When using node-http-handler and setting keep-alive to true in the agent configuration, this setup is not being honored by nodejs https library due to a bug at their side. To aid this issue at the SDK side what I am doing is enabling keep alive directly in the socket, by adding a listener for when a new socket is created, and there we provide the keep-alive settings to the socket. I add this configuration as option so that we need to explicity say we want to enable keep-alive in the socket to keep forward compatibility.
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.
looks good, just need a unit test and some minor changes
Run prettier formatting over the code to make it looks better. Change the name of initialDelay to initialDelayInMSecs to better describe how the value needs to be given. Make initialDelayInMSecs to be optional so that if it is not provided as parameter then it fallbacks into the default value.
Unit tests check the following: - that when keepAlive is provided as true it should set keepAlive to true to the socket. - that when keepAlive is provided as true and a custom initial delay is given they are set correctly. - that when keepAlive is provided as set or not provided at all the keepAlive option is not set to the socket.
Make new changes align with prettier format. Changed: import {setSocketKeepAlive, SocketKeepAliveOptions} from "./set-socket-keep-alive"; To: import { setSocketKeepAlive, SocketKeepAliveOptions, } from "./set-socket-keep-alive";
Is this still a issue? Should we add this work-around in our clients until this is merged, or? |
Refactor the implementation for enabling keepalive in the socket of the request by considering the options passed to the agent provided to the handler.
Ran prettier over the changed files. Updated the logic that decides when we should set keepalive to sockets, in more accurate way.
Verified that keepAlive parameter is set on agent import http from "http";
// Logs false in Node.js 14+
console.log("keepAlive from default agent:", new http.Agent().keepAlive);
// Logs false in Node.js 14+
console.log(
"keepAlive from agent with keepAlive=false:",
new http.Agent({ keepAlive: false }).keepAlive
);
// Logs true in Node.js 14+
console.log(
"keepAlive from agent with keepAlive=true:",
new http.Agent({ keepAlive: true }).keepAlive
); |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread. |
When using node-http-handler and setting keep-alive to true in the agent configuration, this setup is not being honored by nodejs https library, due to a bug with the https lib from nodejs. To aid this issue at the SDK side what I am doing is enabling keep alive directly in the socket, by adding a listener for when a new socket is created, and there we provide the keep-alive settings to the socket.
Issue
Fixes #3624
Description
what I do is to add a listener for when a new socket is created then we pass the keep alive settings to that socket.
Example:
And the configuration above will make the socket to send keep-alive packets every 5 seconds.
Testing
N/A
Additional context
I have also created the following issue under nodejs repo.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.