[X] I have searched for a similar issue in our bug tracker and didn't find any solutions.
What happened?
When using the method Spiral\RoadRunner\GRPC::serve, undesirable behavior related to the persistence of the \Throwable $e variable between iterations of the while loop was discovered. Upon subsequent invocations of the code, the $e variable is preserved, which can lead to unpredictable error handling and execution of code in the finally block, which does not correspond to the expected behavior.
Version (package version)
3.20
How to reproduce the issue?
To reproduce the issue, follow these steps:
Use the method Spiral\RoadRunner\GRPC::serve to start the GRPC server.
In the while loop body that handles requests, trigger an exception (for example, using throw new \Exception('Test Exception');).
Handle the exception in the catch (\Throwable $e) block and perform any actions according to your logic.
Repeatedly invoke the code that initiates the processing of requests to the GRPC server, for example, by sending a new request to the server.
Note that the \Throwable $e variable is preserved between iterations of the while loop, and the code in the finally block may handle previous errors, which can lead to undesirable behavior.
Relevant log output
Solution:
finally {
if ($finalize !== null) {
isset($e) ? $finalize($e) : $finalize();
}
unset($e); // Reset the $e variable
}
No duplicates 🥲.
What happened?
When using the method
Spiral\RoadRunner\GRPC::serve
, undesirable behavior related to the persistence of the\Throwable $e
variable between iterations of thewhile
loop was discovered. Upon subsequent invocations of the code, the$e
variable is preserved, which can lead to unpredictable error handling and execution of code in thefinally
block, which does not correspond to the expected behavior.Version (package version)
3.20
How to reproduce the issue?
To reproduce the issue, follow these steps:
Spiral\RoadRunner\GRPC::serve
to start the GRPC server.while
loop body that handles requests, trigger an exception (for example, usingthrow new \Exception('Test Exception');
).catch (\Throwable $e)
block and perform any actions according to your logic.\Throwable $e
variable is preserved between iterations of thewhile
loop, and the code in thefinally
block may handle previous errors, which can lead to undesirable behavior.Relevant log output
Solution: