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?
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.
You can use timeout in httpOptions. example:
var s3 = new AWS.S3({apiVersion: '2006-03-01', httpOptions: {timeout: 2000}});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With