Skip to content
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

Merged
merged 5 commits into from
Feb 5, 2025

Conversation

nalanj
Copy link
Contributor

@nalanj nalanj commented Feb 4, 2025

Relating to request blocking we were seeing in profiles.

How I tested it

  • made sure oauth2 interactions were still working
  • I manually updated node_modules/simple-oauth2/lib/client/client.js to print the copied config and make sure it included the resulting getter.

@nalanj nalanj self-assigned this Feb 4, 2025
@nalanj nalanj marked this pull request as ready for review February 4, 2025 19:11
@nalanj nalanj requested a review from a team February 4, 2025 19:11
Copy link
Collaborator

@bodinsamuel bodinsamuel left a comment

Choose a reason for hiding this comment

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

let's try

@nalanj nalanj merged commit 97ada7a into master Feb 5, 2025
17 checks passed
@nalanj nalanj deleted the alan/unenumerable-agent branch February 5, 2025 14:06
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 });
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants