Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Prevent exception when parsing request port in ServeCommand #53957

Draft
wants to merge 1 commit into
base: 11.x
Choose a base branch
from

Conversation

anopid
Copy link

@anopid anopid commented Dec 17, 2024

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.

### 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.
@crynobone
Copy link
Member

Mark as draft since it has a merge conflict.

@crynobone crynobone marked this pull request as draft December 17, 2024 23:04
@kerwin-wildsea
Copy link

kerwin-wildsea commented Dec 19, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants