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

I’m getting this error once in a while when making a putObject call.

What is the root cause of the error and what’s the best way to avoid it? According to API response looks like this error is non-retryable. Is there a way to configure aws-sdk to make a retry when this type of error happens?

example response: {“message”:“Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.”,“code”:“RequestTimeout”,“time”:“2014-05-21T00:50:25.709Z”,“statusCode”:400,“retryable”:false,“_willRetry”:false}

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 29 (5 by maintainers)

Commits related to this issue

Most upvoted comments

Now I have pinned point the issue on 2.68.0 <=2.67.0 have no problems.

Further investigation:

The release change on 2.68.0 is:

feature: S3: Switches S3 to use signatureVersion “v4” by default. To continue using signatureVersion “v2”, set the signatureVersion: “v2” option in the S3 service client configuration. Presigned URLs will continue using “v2” by default.

Setting signatureVersion to v2 solve this problem: const s3 = new AWS.S3({signatureVersion: 'v2'});

The followings don’t work: const s3 = new AWS.S3(); => RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed. const s3 = new AWS.S3({signatureVersion:'v4'); => RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed. const s3 = new AWS.S3({signatureVersion:'v3'); => AccessDenied: Access Denied

I don’t have time to debug this, but I got the error as well. I uploaded a file from a website to my server (Node) using Ajax, and then uploaded it from my serverto S3 with code looking like this:

var stream = fs.createReadStream(pathToFile)

s3.putObject({
    Bucket: bucketName,
    Key: key,
    Body: stream
}, function(err, data){ /* Do stuff... */ })

The funny thing is that it always fails for the first Ajax request I send, but it works for all that comes after. I don’t know if this is a bug in the AWS SDK or the package multer (with express) I use to receive the uploaded file on my server (although I receive the file perfectly well as far as I can tell; it’s saved on my server).

However, when I change my code to:

fs.readFile(pathToFile, function(err, data){
    if(err){
        // Handle fail...
    }else{
        s3.putObject({
            Bucket: bucketName,
            Key: key,
            Body: data
        }, function(err, data){ /* Do stuff... */ })
    }
})

It works for all my Ajax request.

I might have done a mistake somewhere (I’m not an experience Node programmer), but hopefully this will help someone.

Anybody fixed this?

It’s quite unbelievable that such commonly used features are faulty after so many years!!! 👎

Is there any work around?

I can only use putObject as the upload method upload 0 byte files (corrupt)

But putObject timeouts if the file is larger then 100 kb.

Is this useless?

Just use s3.upload instead of s3.putObject method. 😉

@paulduthoit Worked! Thanks!

Have the same issue, But when i try signature v2: I get: The authorization mechanism you have provided is not supported. Please use AWS4-HMAC-SHA256

@jeskew, there shouldn’t be any need for a retry if it would work as it should, right? Something is wrong and needs to be fixed? Or am I missing something?

I use a stream to upload a war file to s3 and set the content length with the file size. On slow internet connections (1 Mbps upload) I get this error:

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

I am using version 2.1.33 so the workaround doesn’t work for me.

@lsegal Could you explain me a fix for a stream?