Search code examples
node.jsamazon-s3ceph

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?


Solution

  • 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.