New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQS: receives duplicate messages when Default Visibility Timeout is 0 #705
Comments
After you had receive a message from the queue, do you delete the message using the receipt handle ? If not, the the message appears in the queue after the visibility time out period. |
I do delete the messages. But even the first p.s. I also tested it with |
This seems to be expected behavior when setting a visiblity timeout of 0. No visibility timeout means you aren't reserving the message so it can be picked up by multiple consumers. |
I am aware that the same message might be received by multiple recipients (to provide receive at least once guarantee). The problem is that I get multiple copies of a message within a batch (see above); so please |
My apologies, I see now what you mean. SQS does not guarantee a message is delivered only once and it's required to have idempotent processing. That said it does seem a little surprising you are receiving duplicates in the same batch. I was unable to reproduce, I would only ever get 1 message (or 0 messages due to short polling). This doesn't appear to be an SDK issue so I'll pass this info back to the service team to comment. In the meantime could you provide details on how often you see this and any request ids of affected requests. |
Is your SQS Queue's Default Visibility Timeout set to (if it is set to any other value then there are not dups within the batch). |
Yeah I used the same settings in your screenshot above. |
Still waiting for service team response by the way, I'll ping them again. |
@neil-rubens here's the response from the service team. Would setting a non-zero visibility timeout meet your application's needs? If not could you perhaps code around receiving multiple messages and filter out duplicates?
|
@shorea thank you very much getting the reply from the service team; it explains the duplicate behavior I've encountered. My use case was as following; I am using SQS as a simple semi-persistent job queue for lambda (hence didn't use SNS). I've overcome the issue by simply increasing the wait time; but it took me a while to track down the problem. It could be beneficial to have some pop-up details in the queue settings for the Thank you for your help. |
What about having a distributed system where you have multiple consumers that want to read from the queue at the same time. To be more specific, I have my s3 configured to issue a message to SQS whenever a new file is uploaded. Then I require a number of devices to read that notification and respond accordingly. Now there is no guarantee that these devices are alive when the message is recieved so the queue needs to be asynchronous. Furthermore, the file itself is uploaded by one of these devices. I tried sampling the s3 storage regularly from these devices, but that was too heavy on the CPU. I chose SQS since it has polling, which has almost no CPU usage when the device is waiting for message. |
Isn't there any other way to accomplish this scenario? - Even Im looking to accomplish something similar. I was exploring this option and support saying "setting the visibility timeout to 0 is not a recommended value as it could cause unpredictable behaviour from the service" scares me to use it in production. |
I have
1
message in my SQS queue; however callingReceiveMessageRequest().withMaxNumberOfMessages(10)
returns
3
messages at once (which should be impossible); all of which are duplicates.(expected return should be
1
message).paginator: sqsMsgs.length: 3
Changing
Default Visibility Timeout
: 0 -> 10fixes the problem.
The text was updated successfully, but these errors were encountered: