roadrunner-php / issues

Home for the RoadRunner-PHP issues and discussions ❤️
MIT License
1 stars 0 forks source link

[🐛 BUG]: GRPC Server #32

Open farums opened 2 months ago

farums commented 2 months ago

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 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:

  1. Use the method Spiral\RoadRunner\GRPC::serve to start the GRPC server.
  2. In the while loop body that handles requests, trigger an exception (for example, using throw new \Exception('Test Exception');).
  3. Handle the exception in the catch (\Throwable $e) block and perform any actions according to your logic.
  4. Repeatedly invoke the code that initiates the processing of requests to the GRPC server, for example, by sending a new request to the server.
  5. 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
}
rustatian commented 2 months ago

Hey @farums 👋 All issues should be in English only. Please edit the issue.