-
Notifications
You must be signed in to change notification settings - Fork 465
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix(shared): Keep agents from cloning in simple-oauth2 #3447
Conversation
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.
let's try
const httpConfig = { headers, agents: {} }; | ||
Object.defineProperty(httpConfig.agents, 'http', { get: () => httpAgent, enumerable: true }); | ||
Object.defineProperty(httpConfig.agents, 'https', { get: () => httpsAgent, enumerable: true }); | ||
Object.defineProperty(httpConfig.agents, 'httpsAllowUnauthorized', { get: () => httpsAgent, enumerable: 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 we can simplify and avoid having to use defineProperty
like this:
const getAgentConfig = (): { agents: AgentConfig } => ({
agents: {
get http() { return httpAgent; },
get https() { return httpsAgent; },
get httpsAllowUnauthorized() { return httpsAgent; }
}
});
const clientConfig: Merge<ModuleOptions, { http: WreckHttpOptions }> = {
...,
http: {
headers,
...getAgentConfig()
}
};
And adding a comment to mention the getter dynamic lookup trick used here. I am sure next week I am gonna have forgotten about it already
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 had already hit merge but I'll put a follow-up in real quick and merge it if this works out for that hot spot in the profiles, otherwise we'll just revert.
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.
Relating to request blocking we were seeing in profiles.
How I tested it
node_modules/simple-oauth2/lib/client/client.js
to print the copied config and make sure it included the resulting getter.