Recursive loops Detected and Stopped for Lambda Function guidance in our scenario

0

We have deployed a standard AWS SQS queue.This queue is configured to retain messages for 4 days.

Message processing: Once message is received by the consumer(lambda with reserve concurrency = 5), consumer checks where the message processable or not. If not,we update the message visibility time and terminate the process without deleting the message by throwing error(assuming that the termination will retain the message).

Doubts:

  1. Retention period is set to 4 days but sometimes message stays in queue for longer time. How is it possible?

  2. How ApproximateReceiveCount is maintained. We observed that there are gaps in values in sequential message processing. for eg. ApproximateReceiveCount = 9 in one message and same value is set to 3 in previous message for same messageID.

  3. AWS documentation says recursive loop detection happens after 16th iteration, however we have observed even with ApproximateReceiveCount = 18, we have not got any alert.

Mayank
asked a month ago112 views
1 Answer
0

How did you check that retention is not accurate?

Due to the distributed nature of SQS, ApproximateReceiveCount is only an approximation (as it names implies). Different hosts can have different values.

What you are doing is not consider recursive invocation. A recursive use case if if your function sends the messages back to the same queue. This can cause an infinite loop. Not deleting the message from the queue is not a recursive operation as eventually it will either hit the maximum retries or will expire from the queue.

Instead of failing your function, you can just return an array with partial batch responses.

profile pictureAWS
EXPERT
Uri
answered a month ago
profile picture
EXPERT
reviewed a month ago
  • How did you check that retention is not accurate? -> We have a retention set on queue of 4 days. But we observed that message is being retained for than 4 days by looking at logs for specific message id.

    We received recursive invocation mail from aws hence it is considered as recursive invocation. Before failing the execution, visibility timeout of message is increased and then execution is failed, that way message stays in the queue but invocation counter is increased.

    Is there any way to keep the message in the queue without becoming a case for recursive invocation?

  • This is strange. Not handling a message is not a recursion. I am guessing that you are sending the message to the queue again yourself. This will explain the recursion message you got as well as the fact that it stays for more than 4 days. Can you share your code?

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions