Skip to content

Bug: Retry of previously failed SQS record is skipped when skipGroupOnError is enabled #3673

Closed
@mlrprananta

Description

@mlrprananta

Expected Behavior

When a SQS record that failed in a previous Lambda invocation is retried and handled by the same Lambda instance again, it should be processed by the provided recordHandler

Current Behavior

When a SQS record that failed in a previous Lambda batch invocation is retried and handled by the same Lambda instance again, it is skipped and returned as a failure without going through the recordHandler.

Only if the record is handled by a concurrent Lambda instance will it be processed again.

Code snippet

import { processPartialResponse, SqsFifoPartialProcessorAsync } from "@aws-lambda-powertools/batch";
import { SQSHandler, SQSRecord } from "aws-lambda";

const processor = new SqsFifoPartialProcessorAsync();

const recordHandler = async (record: SQSRecord): Promise<void> => {
    console.debug("RECORD HANDLER INVOKED");
    throw new Error("Random error occurred");
};

export const handle: SQSHandler = async (event, context) => {
    console.debug('SQS HANDLER INVOKED');
    return processPartialResponse(event, recordHandler, processor, {
        context,
        skipGroupOnError: true,
        throwOnFullBatchFailure: false,
    });
};

Steps to Reproduce

  1. Set up a FIFO queue, a DLQ and a Lambda with the above handler code and set reserved concurrency to 0
  2. Publish any message to the queue
  3. In the logs you should observe SQS HANDLER INVOKED and RECORD HANDLER INVOKED for the first invocation, and after the visibility timeout it will only log SQS HANDLER INVOKED for follow-up invocations, until maxReceiveCount is hit and the message is moved to the DLQ

Possible Solution

In SqsProcessor, the failedGroupIds should be cleared after each Lambda invocation.

Introduce a method to clear the failedGroupIds in SqsProcesor.

In SqsFifoPartialProcessorAsync override the prepare method and add a call to clear failedGroupIds.

Powertools for AWS Lambda (TypeScript) version

latest

AWS Lambda function runtime

18.x

Packaging format used

npm

Execution logs

Metadata

Metadata

Assignees

Labels

batchThis item relates to the Batch Processing UtilitybugSomething isn't workingcompletedThis item is complete and has been merged/shipped

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions