https://serverless-stack.com/ logo
#help
Title
# help
u

Uday Bhaskar Gajavalli

04/12/2022, 6:49 AM
Hello, I have created a queue and attached to lambda function but somehow the consumer lambda is invoking twice though I was manually deleting the message after processing. Could any one help me with this?
@Frank
f

Frank

04/12/2022, 2:43 PM
Hey @Uday Bhaskar Gajavalli is it happening on
sst start
or after
sst deploy
?
u

Uday Bhaskar Gajavalli

04/12/2022, 2:43 PM
it's in sst start
We have multiple queues and their respective consumer functions. Still facing the same issue
f

Frank

04/12/2022, 2:47 PM
If you look in ur terminal, u see the consumer invoked twice?
Do both invocations have the same or different request id?
u

Uday Bhaskar Gajavalli

04/12/2022, 2:50 PM
It has different request ids
f

Frank

04/12/2022, 2:52 PM
I see. How long is it between the two requests?
u

Uday Bhaskar Gajavalli

04/12/2022, 2:54 PM
Less than a second or 2 seconds
f

Frank

04/12/2022, 2:54 PM
could it be that the same message was sent twice to the queue?
u

Uday Bhaskar Gajavalli

04/12/2022, 2:56 PM
Queue is only getting 1 message but somehow the consumer is invoking twice and also I have written logic for deleting message from queue after processing in the consumer functions
though the the consumer is invoking second time
f

Frank

04/12/2022, 2:56 PM
hmm u shouldn’t have to delete manually, that’s done automatically
Can i see how u r creating the queue?
u

Uday Bhaskar Gajavalli

04/12/2022, 2:57 PM
Copy code
const clickQueue = new sst.Queue(this, "clickQueue", {
      consumer: {
        handler:
          "path",
        timeout: 10,
      },
      sqsQueue: {
        visibilityTimeout: Duration.seconds(30),
      },
    });
f

Frank

04/12/2022, 2:58 PM
that looks right to me..
one thing I’d check is if u look at the xray trace for one of the consumer invocation, can you share what u see there?
u

Uday Bhaskar Gajavalli

04/12/2022, 3:00 PM
Let me check there too
f

Frank

04/12/2022, 3:00 PM
Yeah, I wonder if the request has failed and Lambda is doing a retry
u

Uday Bhaskar Gajavalli

04/12/2022, 3:02 PM
import { SQSEvent } from _"aws-lambda"_;
export async function clickQueueConsumer(
_event_: SQSEvent) {
const failedMessageIds = []; for (const record of event.Records) { try { console.log(
_"clickQueueConsumer: "_, record.body);
} catch (e) { failedMessageIds.push(record.messageId); } } return { batchItemFailures: failedMessageIds.map((
_id_) => {
return { itemIdentifier: id, }; }), }; }
f

Frank

04/12/2022, 3:04 PM
Can you try commenting out everything, just an empty function, see if it gets call twice.
Copy code
export async function clickQueueConsumer() {
 console.log("called");
}
u

Uday Bhaskar Gajavalli

04/12/2022, 3:07 PM
Yeah it's getting called twice
f

Frank

04/12/2022, 3:07 PM
hmm.. that’s really weird
Yeah if u can look up xray, that should tell us if SQS is calling the consumer twice or if it’s a Lambda retry
u

Uday Bhaskar Gajavalli

04/12/2022, 3:09 PM
Unfortunately, I don't have access to view X-Ray
I found this from the Log groups of the clickQueueConsumer function receiveMessage() - stop keep alive timer Timeout { _idleTimeout: 540000, _idlePrev: [TimersList], _idleNext: [TimersList], _idleStart: 494, _onTimeout: [Function (anonymous)], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: true, [Symbol(kHasPrimitive)]: false, [Symbol(asyncId)]: 19, [Symbol(triggerId)]: 5 }
f

Frank

04/12/2022, 3:12 PM
Can u share the entire log of a request?
u

Uday Bhaskar Gajavalli

04/12/2022, 3:16 PM
START RequestId: fcc73f27-8219-5ad9-ac7c-65e815b62d58 Version: $LATEST 2022-04-12T150640.065Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO connectAndSendMessage() 2022-04-12T150640.142Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO ws.onopen 2022-04-12T150640.142Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO sendMessage() - send request 2022-04-12T150640.144Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO sendMessage() - sending request via WebSocket 2022-04-12T150640.145Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO sendMessage() - start keep alive timer 2022-04-12T150645.371Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO ws.onmessage { "action": "client.lambdaResponse", "debugRequestId": "fcc73f27-8219-5ad9-ac7c-65e815b62d58-1649776000065", "stubConnectionId": "QeRMDfhtoAMCLww=", "payload": "H4sIAAAAAAAACqtWKkotLsjPK051SSxJVLLKK83JqQUACtSALhUAAAA=" } 2022-04-12T150645.371Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO receiveMessage() 2022-04-12T150645.371Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO receiveMessage() - received payload 2022-04-12T150645.374Z fcc73f27-8219-5ad9-ac7c-65e815b62d58 INFO receiveMessage() - stop keep alive timer Timeout { _idleTimeout: 540000, _idlePrev: [TimersList], _idleNext: [TimersList], _idleStart: 494, _onTimeout: [Function (anonymous)], _timerArgs: undefined, _repeat: null, _destroyed: false, [Symbol(refed)]: true, [Symbol(kHasPrimitive)]: false, [Symbol(asyncId)]: 19, [Symbol(triggerId)]: 5 } END RequestId: fcc73f27-8219-5ad9-ac7c-65e815b62d58 REPORT RequestId: fcc73f27-8219-5ad9-ac7c-65e815b62d58 Duration: 5312.22 ms Billed Duration: 5313 ms Memory Size: 1024 MB Max Memory Used: 81 MB Init Duration: 472.61 ms XRAY TraceId: 1-6255957f-612a77240c203fd10acb1f44 SegmentId: 61e68ede2e99e67d Sampled: true
f

Frank

04/12/2022, 3:18 PM
it looks fine
And there’s another request right after this with the same
event
?
u

Uday Bhaskar Gajavalli

04/12/2022, 3:19 PM
Is it normal?
sendMessage()
in consumerfunction log
Yeah the same event but with different requestId
f

Frank

04/12/2022, 3:20 PM
yeah, it’s a stub Lambda, and it’s sending a websocket message to ur local with the request info.
u

Uday Bhaskar Gajavalli

04/12/2022, 3:20 PM
Ohh Okay.
f

Frank

04/12/2022, 3:22 PM
Does this happen to all queues in ur app?
u

Uday Bhaskar Gajavalli

04/12/2022, 3:22 PM
Yes. for every queue
f

Frank

04/12/2022, 3:26 PM
hmm.. a couple of things I’d try: • set Lambda retry to 0 (disable retry) => this tells us if the 2nd request is a retry • removing the Lambda consumer, and after u call sendMessage, go to AWS SQS console and inspect the queue => this tells us if the same message is sent twice • create a new SST app with just a queue and see if the same issue can be reproduced. You can use this sample repo.
u

Uday Bhaskar Gajavalli

04/12/2022, 3:30 PM
Can we set the lambda retry to 0 from SST or should I do it from AWS Console?
I have removed the consumer and somehow same message is sent twice into the queue
j

Jay

04/18/2022, 11:08 PM
Are you still having this issue @Uday Bhaskar Gajavalli?