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

[10.x] Set IP:PORT as key to $requestsPool on ServeCommand #46740

Closed
wants to merge 1 commit into from
Closed

[10.x] Set IP:PORT as key to $requestsPool on ServeCommand #46740

wants to merge 1 commit into from

Conversation

eusonlito
Copy link
Contributor

@eusonlito eusonlito commented Apr 11, 2023

Related with the issue #46726.

The previous PR only avoid the error when the process output try to write on a port previously closed by a different request.

Currently the $requestsPool array on Illuminate\Foundation\Console\ServeCommand is handling the requests using only the port, but requests can reuse the same port, then different request from different clients (IP) would be handled as same request.

php artisan serve --host=0.0.0.0 --port=80 >> storage/logs/artisan-serve.log 2>&1
[2023-04-11 10:52:07] stage.DEBUG: [Tue Apr 11 08:52:07 2023] XXX.XXX.XXX.214:42202 Accepted
[2023-04-11 10:52:07] stage.DEBUG: [Tue Apr 11 08:52:07 2023] XXX.XXX.XXX.212:32768 Accepted # Accepted Request 1 on port 32768
[2023-04-11 10:52:07] stage.DEBUG:
[2023-04-11 10:52:10] stage.DEBUG: [Tue Apr 11 08:52:10 2023] XXX.XXX.XXX.214:42202 Closing
[2023-04-11 10:52:10] stage.DEBUG: [Tue Apr 11 08:52:10 2023] XXX.XXX.XXX.218:32768 Accepted # Accepted Request 2 on port 32768
[2023-04-11 10:52:10] stage.DEBUG:
[2023-04-11 10:52:10] stage.DEBUG: [Tue Apr 11 08:52:10 2023] XXX.XXX.XXX.212:32768 Closing # Closing Request 1 on port 32768
[2023-04-11 10:52:10] stage.DEBUG: [Tue Apr 11 08:52:10 2023] XXX.XXX.XXX.218:32768 Closing # Request 2 can not be managed because the port was closed (removed from `$requestsPool` when closing Request 1).
[2023-04-11 10:52:11] stage.ERROR: Undefined array key 32768 {"exception":"[object] (ErrorException(code: 0): Undefined array key 32768 at /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/ServeCommand.php:255)
[stacktrace]
#4 /app/vendor/symfony/process/Process.php(1272): Illuminate\\Foundation\\Console\\ServeCommand->Illuminate\\Foundation\\Console\\{closure}('err', '[Tue Apr 11 08:...')
#5 /app/vendor/symfony/process/Process.php(1370): Symfony\\Component\\Process\\Process->Symfony\\Component\\Process\\{closure}('err', '[Tue Apr 11 08:...')
#6 /app/vendor/symfony/process/Process.php(1290): Symfony\\Component\\Process\\Process->readPipes(false, true)
#7 /app/vendor/symfony/process/Process.php(838): Symfony\\Component\\Process\\Process->updateStatus(false)
#15 /app/vendor/symfony/console/Command/Command.php(312): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#17 /app/vendor/symfony/console/Application.php(1040): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#18 /app/vendor/symfony/console/Application.php(314): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Foundation\\Console\\ServeCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#19 /app/vendor/symfony/console/Application.php(168): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#21 /app/artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#22 {main}
"}
[2023-04-11 10:52:11] stage.DEBUG: [Tue Apr 11 08:52:11 2023] PHP 8.1.17 Development Server (http://0.0.0.0:80) started

This PR adds the IP as part of $requestsPool.

This PR also factorizes the handleProcessOutput method to avoid too much complexity in a single function moving every possible output to a own method (the code wasn't changed on every output type, only was moved to a new method).

@eusonlito eusonlito changed the title [10.x] Set IP:PORT as key to $requestsPool on ServeCommand. Related #46726 [10.x] Set IP:PORT as key to $requestsPool on ServeCommand Apr 11, 2023
@taylorotwell
Copy link
Member

Too much other refactoring in this PR.

@eusonlito
Copy link
Contributor Author

eusonlito commented Apr 11, 2023

Ok @taylorotwell, maybe a PR only with $requestsPool key fix?

And.. do you want a different PR with refactoring, or only the PR with the fix?

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.

2 participants