Skip to content

@aws-sdk/client-s3 RequestTimeout error in PutObjectCommand #6762

@somnathPrasad

Description

@somnathPrasad

Checkboxes for prior research

Describe the bug

I am trying to upload an image file to a public s3 bucket. But every time I get this error, even when trying to upload a very small file (eg: 130kb)

RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.

This is the code block

const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3");
const config = require("../../config/config");

const { FILEUPLOADERROR, UPLOAD_SUCCESS } = config.response;
const { accessKeyId, region, secretAccessKey, public_bucket } =
  config.aws_config;

const s3Client = new S3Client({
  credentials: { accessKeyId, secretAccessKey },
  region,
});

module.exports = {
  uploadFilePublic: async (folderName, fileName, file) => {
    try {
      const date = new Date().valueOf();
      const fileType = file.mimetype.split("/")[1];
      const key = `${folderName}/${fileName}_${date}.${fileType}`;
      const downloadUrl = `https://${public_bucket}.s3.${region}.amazonaws.com/${key}`;

      const params = {
        Bucket: public_bucket,
        Key: key,
        Body: file.data,
      };

      const command = new PutObjectCommand(params);
      await s3Client.send(command);

      return {
        status: true,
        message: UPLOAD_SUCCESS,
        result: {
          name: file.name,
          type: file.mimetype,
          url: downloadUrl,
        },
      };
    } catch (error) {
      console.log(FILEUPLOADERROR, error);
      return { status: false, message: FILEUPLOADERROR };
    }
  },
};

But this is working in the old aws package "aws-sdk": "^2.962.0"

Regression Issue

  • Select this option if this issue appears to be a regression.

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v20.17.0

Reproduction Steps

The same bug can be reproduced through the above code.

Observed Behavior

I am getting this error.

RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.
    at throwDefaultError (D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\client-s3\node_modules\@smithy\smithy-client\dist-cjs\index.js:835:20)
    at D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\client-s3\node_modules\@smithy\smithy-client\dist-cjs\index.js:844:5
    at de_CommandError (D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\client-s3\dist-cjs\index.js:4919:14)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\client-s3\node_modules\@smithy\middleware-serde\dist-cjs\index.js:35:20
    at async D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\middleware-sdk-s3\dist-cjs\index.js:485:18
    at async D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\client-s3\node_modules\@smithy\middleware-retry\dist-cjs\index.js:320:38
    at async D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\middleware-flexible-checksums\dist-cjs\index.js:286:18
    at async D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\middleware-sdk-s3\dist-cjs\index.js:110:22
    at async D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\middleware-sdk-s3\dist-cjs\index.js:138:14
    at async D:\appstone\imgrows_v2\backend\node_modules\@aws-sdk\client-s3\node_modules\@aws-sdk\middleware-logger\dist-cjs\index.js:34:22
    at async Object.uploadFilePublic (D:\appstone\imgrows_v2\backend\src\modules\v3\file-upload-module.js:29:7)
    at async Object.updateUserV2 (D:\appstone\imgrows_v2\backend\src\modules\v3\user-module.js:514:36)
    at async D:\appstone\imgrows_v2\backend\src\routes\v3\user-route.js:198:22 {
  '$fault': 'client',
  '$metadata': {
    httpStatusCode: 400,
    requestId: 'WCVYSEKRWW9G3E6Z',
    extendedRequestId: 'ceYIY8UWyWWZqU3QTW3QmM2CNJBvby7BGpSz6yoQ5kZmK6Zx+cvieiG4LeEHIiwUAFUDzJM1bR0=',
    cfId: undefined,
    attempts: 3,
    totalRetryDelay: 116
  },
  Code: 'RequestTimeout',
  RequestId: 'WCVYSEKRWW9G3E6Z',
  HostId: 'ceYIY8UWyWWZqU3QTW3QmM2CNJBvby7BGpSz6yoQ5kZmK6Zx+cvieiG4LeEHIiwUAFUDzJM1bR0='
}

Expected Behavior

I expected it to upload file to s3 and not give any errors

Possible Solution

No response

Additional Information/Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis issue is a bug.needs-triageThis issue or PR still needs to be triaged.potential-regressionMarking this issue as a potential regression to be checked by team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions