runtime icon indicating copy to clipboard operation
runtime copied to clipboard

[Bref] Added support for handle timeouts

Open Nyholm opened this issue 2 years ago • 2 comments

We want to give the application some time to cleanup and write logs.

This feature was originally suggested in https://github.com/brefphp/bref/pull/895, but it has not been merged because it did not work with the PHP-FPM layer. We are not using PHP-FPM so we are good to go.

Nyholm avatar Oct 06 '21 03:10 Nyholm

After #94 is merged, we should add a version of the following test in LambdaClientTest:

public function testLambdaTimeoutsCanBeAnticipated()
    {
        $this->givenAnEvent([]);

        $start = microtime(true);
        $this->runtime->processNextEvent(function () {
            // This 10s sleep should be interrupted
            sleep(10);
        });

        $elapsedTime = microtime(true) - $start;
        // The Lambda timeout was 2 seconds, we expect the Bref timeout to trigger 1 second before that: 1 second
        $this->assertEqualsWithDelta(1, $elapsedTime, 0.2);
        Timeout::reset();

        $this->assertInvocationErrorResult(LambdaTimeout::class, 'Maximum AWS Lambda execution time reached');
        $this->assertErrorInLogs(LambdaTimeout::class, 'Maximum AWS Lambda execution time reached');
    }

Nyholm avatar Oct 06 '21 04:10 Nyholm

I reverted some functionality. See ceb19a5853de0f5fa8fdad1d52648bebad5a73e0. This should be fixed or we need to update the docs.

I get a segfault (9 and 10) in PHP when symfony trying to invoke the error_controller. Im not sure why. It may be related to that we throw an exception in a pcntl_signal-handler. It got randomly (not always) better when I removed the stack trace from the exception.

When I test a small app (as in the current docs) then it works perfectly.. hm..

Nyholm avatar Oct 07 '21 05:10 Nyholm