From 5f322a7485ed95a322b74c406ccd4d62322b9bb8 Mon Sep 17 00:00:00 2001 From: Nyholm Date: Tue, 30 Mar 2021 14:05:01 +0200 Subject: [PATCH] Make sure second alarm is not triggered --- src/Timeout/Timeout.php | 6 ++++-- tests/Timeout/TimeoutTest.php | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Timeout/Timeout.php b/src/Timeout/Timeout.php index 8bbd9a582..275fbdf4f 100644 --- a/src/Timeout/Timeout.php +++ b/src/Timeout/Timeout.php @@ -10,7 +10,9 @@ final class Timeout { /** @var bool */ private static $initialized = false; - private static $stackTrace; + + /** @var string|null */ + private static $stackTrace = null; /** * Automatically setup a timeout (based on the AWS Lambda timeout). @@ -70,7 +72,7 @@ private static function init(): void if (Timeout::$stackTrace !== null) { // we already thrown an exception. error_log('Lambda timed out'); - error_log((new LambdaTimeout())->getTraceAsString()); + error_log((new LambdaTimeout)->getTraceAsString()); error_log('Original stack trace'); error_log(Timeout::$stackTrace); Timeout::$stackTrace = null; diff --git a/tests/Timeout/TimeoutTest.php b/tests/Timeout/TimeoutTest.php index f52774172..4bc06085e 100644 --- a/tests/Timeout/TimeoutTest.php +++ b/tests/Timeout/TimeoutTest.php @@ -60,6 +60,7 @@ public function test timeouts are interrupted in time() } catch (LambdaTimeout $e) { $time = 1000 * (microtime(true) - $start); $this->assertEqualsWithDelta(2000, $time, 200, 'We must wait about 1 second'); + Timeout::reset(); } catch (\Throwable $e) { $this->fail('It must throw a LambdaTimeout.'); }