brefphp / bref

Serverless PHP on AWS Lambda
https://bref.sh
MIT License
3.1k stars 367 forks source link

exit; in SQS event #1639

Closed eroltoker closed 12 months ago

eroltoker commented 1 year ago

In the following scenario, it appears that the invoked lambda function gets stuck in an infinite loop.

At first I thought maybe it was just that the SQS event wasn't being popped off the queue because of the way this is killing the php script. However, while the infinite loop is occurring, I purged the SQS queue and the lambda function remained stuck in the infinite loops for over 2 minutes until it eventually timed out.

In this case I had a bug in my development (I don't run production code doing 'exit' like this), however it seems a bad design to have a situation where infinite loop like this can be introduced (especially in dev environments where exit may be used in debugging), since lambdas can't be manually stopped -- the remedy is tearing down the entire cloudformation stack which is a pain in the behind.

use Bref\Context\Context; use Bref\Event\Sqs\SqsEvent; use Bref\Event\Sqs\SqsHandler;

class Handler extends SqsHandler { public function handleSqs(SqsEvent $event, Context $context): void { exit; }
}

mnapoli commented 1 year ago

Hi, unfortunately calling exit breaks how Lambda works. What would you imagine happening ideally?

eroltoker commented 1 year ago

To make a suggestion of what should happen ideally, would be helpful to understand exactly why exit; is breaking lambda? I would expect if lambda 'broke', the infinite loop would manifest as constant spawning of new invocations, not an infinite loop within one invocation. If the process itself isn't dying, i would expect some error handling indicating the same SQS event is being consumed in a manner that seems wrong. But again, hard to make a concrete suggestion without knowing the cause of the issue.