Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to cut out connection for aws sdk s3 after predefined time?

I'm using aws-sdk module in my node app,
specifically the S3 library, to write to a ceph cluster.

The application upload fixed size files periodically.
The ceph perform sharding sometimes, which cause the http upload request to stall for 500 seconds.
How can I cancel those requests for buckets that performing sharding?
How can I set a timeout for, say 2 seconds, for all the uploads?

like image 996
natdev Avatar asked Oct 23 '25 22:10

natdev


2 Answers

After searching the web for a long time, I found this abort function.

So, if it help anyone, this is how I implemented it:

const upload = (bucket, key, body, timeout = 2000) => {
  const request = this.s3.upload({Bucket: bucket, Key: key, Body: body})
  setTimeout(request.abort.bind(request), timeout)
  return request.promise()
}

If timeout passed, then an Error is thrown with RequestAbortedError code.

like image 184
natdev Avatar answered Oct 25 '25 12:10

natdev


You can use timeout in httpOptions. example:

var s3 = new AWS.S3({apiVersion: '2006-03-01', httpOptions: {timeout: 2000}});
like image 24
Seena Fallah Avatar answered Oct 25 '25 13:10

Seena Fallah



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!