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

AWS.NodeHttpClient use undefined httpAgent instead of default one #4452

Closed
pivstone opened this issue Jun 21, 2023 · 4 comments
Closed

AWS.NodeHttpClient use undefined httpAgent instead of default one #4452

pivstone opened this issue Jun 21, 2023 · 4 comments
Assignees
Labels
bug This issue is a bug. p2 This is a standard priority issue

Comments

@pivstone
Copy link
Contributor

pivstone commented Jun 21, 2023

Describe the bug

when a user pass agent: undefined to a client (us DynamoDB as example).

import AWS from 'aws-sdk';
const options = {
    apiVersion: '2012-10-08',
    httpOptions: {
      agent: undefined
    },
  }
new AWS.DynamoDB.DocumentClient(options);

AWS.NodeHttpClient set a default agent in here.

if (!httpOptions.agent) {
options.agent = this.getAgent(useSSL, {
keepAlive: process.env[CONNECTION_REUSE_ENV_NAME] === '1' ? true : false
});
}

but the in the next line options.agent is updated to undefined by this line.

AWS.util.update(options, httpOptions);

Because the httpOptions.agent is undefined.

Expected Behavior

The http agent shouldn't be undefined.

Current Behavior

The http agent is undefined.

Reproduction Steps

as the description

Possible Solution

AWS.util.update(options, httpOptions);

should be executed before assign the default http agent instance.

A suggest fix: #4453

Additional Information/Context

No response

SDK version used

2.1374.0

Environment details (OS name and version, etc.)

Lambda/NodeJs 16

@pivstone pivstone added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jun 21, 2023
@RanVaknin
Copy link
Contributor

Hi @pivstone ,

Thanks for the feedback and the PR, on a first glance it looks good.
We will review this and get back to you.

Thanks,
Ran~

@RanVaknin RanVaknin self-assigned this Jun 21, 2023
@RanVaknin RanVaknin added needs-review This issue/pr needs review from an internal developer. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jun 21, 2023
@kuhe
Copy link
Contributor

kuhe commented Jun 23, 2023

What is the scenario where you pass undefined to the agent?

@kuhe kuhe added response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. and removed needs-review This issue/pr needs review from an internal developer. labels Jun 23, 2023
@pivstone
Copy link
Contributor Author

What is the scenario where you pass undefined to the agent?

We have an internal library dynamodb client for all our AWS Lambda, something like this.

type BaseOptions = {
  maxRetries?: number;
  timeoutMs?: number;
  httpsAgent?: httpsAgent;
};

function buildOption(options: BaseOptions) {
  return {
    apiVersion: '2012-10-08',
    convertEmptyValues: true,
    maxRetries: options.maxRetries ?? 3,
    httpOptions: {
      agent: options.httpsAgent ?? undefined,
      timeout: options.timeoutMs ?? 3000,
    },
  };
}

new AWS.DynamoDB.DocumentClient(buildOption(options));

we added the httpOptions. agent as the an optional parameter, because the sdk accept an undefined, so we think it's fine to use undefined as default value, then we found the latency of calling dynamodb increased from few ms to 22ms.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to \"closing-soon\" in 7 days. label Jun 24, 2023
@RanVaknin
Copy link
Contributor

PR merged. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

3 participants