Skip to content

[node-http-handler 100-continue] When an error occurs in the request, there is no waiting time for the cotinue event #4799

Closed
@bcshmily

Description

@bcshmily

Checkboxes for prior research

Describe the bug

When an error occurs in the request, there is no waiting time for the cotinue event,
If the socketTimeout set is relatively long, Lambda will timeout

SDK version number

@aws-sdk/node-http-handler": "3.344.0"

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v18.16.0

Reproduction Steps

set socketTimeout of S3Client  to 15 minute
s3 = new S3Client({
      apiVersion: "2006-03-01",
      requestHandler: new NodeHttpHandler({
        socketTimeout: 15 * 60 * 1000
      }),
    });

Usually, uploading files only takes one minute, but sometimes Lambda times out

    const parallelUploadS3 = new Upload({
      client: s3,
      params: {
        Bucket: bucket,
        Key: key,
        Body: body
      }
    });
    await parallelUploadS3.done();

Observed Behavior

Lambda timeout

Expected Behavior

The file can be uploaded successfully

Possible Solution

Possible reason: When an error occurs in the request, there is no waiting time for the cotinue event, so the configured 15 minute timeout will be applied

packages/node-http-handler/src/write-request-body.ts

export async function writeRequestBody(
  httpRequest: ClientRequest | ClientHttp2Stream,
  request: HttpRequest,
  maxContinueTimeoutMs = MIN_WAIT_TIME
): Promise<void> {
  const headers = request.headers ?? {};
  const expect = headers["Expect"] || headers["expect"];

  let timeoutId = -1;
  let hasError = false;
  if (expect === "100-continue") {
    await Promise.race<void>([
      new Promise((resolve) => {
        timeoutId = Number(setTimeout(resolve, Math.max(MIN_WAIT_TIME, maxContinueTimeoutMs)));
      }),
      new Promise((resolve) => {
        httpRequest.on("continue", () => {
          clearTimeout(timeoutId);
          resolve();
        });
        httpRequest.on("error", () => {
          hasError = true;
          clearTimeout(timeoutId);
          resolve();
        });
      }),
    ]);
  }
  if(!hasError) {
      writeBody(httpRequest, request.body);
  }
}

Additional Information/Context

v3.329.0 is work fine.

Metadata

Metadata

Labels

bugThis issue is a bug.closing-soonThis issue will automatically close in 4 days unless further comments are made.p2This is a standard priority issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions