[BUG]: handleMessage is called twice at the same time. #433
-
SummaryHello, I've encountered a bug that results in the handleMessage function being invoked twice simultaneously. My application utilizes the sqs-consumer library in the following manner:
The relevant part of the code looks like this: import { range } from 'lodash';
import { Consumer } from 'sqs-consumer';
const numOfConsumers = process.env.NUMBER_OF_CONSUMERS ? parseInt(process.env.NUMBER_OF_CONSUMERS) : 1;
let sqsConsumers;
sqsConsumers = range(numOfConsumers).map((consumerNumber) => {
return Consumer.create({
// more options.
handleMessage: async (sqsMessage: AWS.SQS.Message) => {
// We use cls-hooked with runAndReturn
return cls.run(() => {
const {
Attributes: { ApproximateReceiveCount: receiveCount },
ReceiptHandle: receiptHandle,
Body: rawBody,
MessageId: sqsMessageId,
} = sqsMessage;
logger.log({
message: 'Running an SQS message by consumer number #' + consumerNumber,
consumerNumber,
MessageId: sqsMessageId,
receiveCount,
});
// Code to handle the message
});
})
},
}); I have observed that this function is called twice because my logs show two identical entries originating from the same machine at the same time. Additionally, both the receiveCount and consumerNumber values are the same for these entries. The bug is quite rare, occurring in only 0.0275% of the messages, specifically in 2750 out of 10 million messages. At this point, I don't have a clear method for reproducing the issue, and I'm not aware of any apparent culprits in the code. The problem could be related to the library itself, or it might be connected to the interaction between Has anyone else encountered or observed a similar issue? ExampleNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I'm not entirely sure but also, we don't really have anything specific in SQS Consumer for multiple instances of it, so it may just be that the code hasn't really been built to handle this. Will have to be investigated. |
Beta Was this translation helpful? Give feedback.
I'm not entirely sure but also, we don't really have anything specific in SQS Consumer for multiple instances of it, so it may just be that the code hasn't really been built to handle this.
Will have to be investigated.