aws-sdk-js: Sporadic slow sendMessage calls to SQS via lambda

Confirm by changing [ ] to [x] below:

Describe the question We’ve recently switched from using the Java SDK to the Javascript SDK when sending messages to SQS. Since we’ve done that, we’ve noticed that sometimes some of our requests are taking awhile to return. Not a huge amount, maybe 1 in every 1000 or so calls but it’s noticeable in various aspects of our product.

We are a lambda based Node 10 project using aws-sdk 2.784.0. Here’s an example of one of our logs:

@message | 2020-11-15T00:30:13.036Z-info : "Finished posting next message for run 5fb075bed23530000700a3cd and node sixxim in 11127(ms)"

So that finished in 11 seconds. The other 999 entries in this log (which spans 12 hours so it’s not a lot per minute) all finished in about 50ms.

Our code to send messages is pretty simple:

const agent = new https.Agent({
  timeout: 5000,
})

export class SQSHelper {
  readonly sqs: SQS

  constructor(sqs?: SQS) {
    this.sqs =
      sqs ||
      new SQS({
        httpOptions: {
          timeout: 5000,
          connectTimeout: 3000,
          agent: agent,
        },
      })
  }

  public async postMessage(queue: string, message: string): Promise<SendMessageResult> {
    return new Promise((resolve, reject) => {
      this.sqs.sendMessage({ QueueUrl: queue, MessageBody: message }, (err, data) => {
        if (err) {
          reject(err)
        } else {
          resolve(data)
        }
      })
    })
  }
}

const sqsHelper = new SQSHelper()
export default sqsHelper

I guess what i’m hoping for info on is:

  1. What could possibly cause this?
  2. Is there anyway to add handling to our typescript code so that we can log what errors are causing the hangs?

I’ve found https://github.com/aws/aws-sdk-js/issues/2912 which allows us to see when we retried but I can’t seem to find out why we retried.

Any help would be greatly appreciated. Thanks.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 32 (11 by maintainers)

Most upvoted comments

Currently using aws-sdk: 2.302.0. Node version 12.

You are right with your last reply, I was still looking at just sendMessage, but I read the original post again, to start with can you update the SDK to the latest version?

Okay, I will update the SDK to the latest version and will check if the problem still persists.