framework icon indicating copy to clipboard operation
framework copied to clipboard

Fix: Prevent exception when parsing request port in ServeCommand

Open anopid opened this issue 11 months ago • 2 comments

Summary

This PR fixes an issue where php artisan serve throws an exception on Windows when a log line does not contain a valid request port.

Problem

"process forking is not supported" when running the "artisan serve", and the flushOutputBuffer method tries to parse invalid lines. This raises the exception

Solution

  • Added a guard condition to check if the line contains the expected keywords (Accepted, Closing) before calling getRequestPortFromLine.
  • Ensured no exception is thrown for invalid lines.

Changes Made

  • Updated flushOutputBuffer method in ServeCommand.php:
    • Added contains() checks for specific keywords.
    • Skipped port parsing for invalid lines.

How to Test

  1. Run php artisan serve.
  2. Verify that no exception occurs when invalid lines are logged.
  3. Check that server output behaves as expected.

anopid avatar Dec 17 '24 22:12 anopid

Mark as draft since it has a merge conflict.

crynobone avatar Dec 17 '24 23:12 crynobone

The error "Failed to extract the request port" is caused by the change from #53887. Which has been reverted in the latest release 11.36.1.

In that PR behaviour was changed by pulling out the common logic of getting the port from a line. Which, previously was behind if-statements.

This PR might not be necessary if #53887 is adjusted so that static::getRequestPortFromLine is not called outside of the if statements again, or if it is not re-introduced.

kerwin-wildsea avatar Dec 19 '24 10:12 kerwin-wildsea