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] Fixed server Closing output on invalid $requestPort #46726

Merged
merged 1 commit into from
Apr 10, 2023
Merged

[10.x] Fixed server Closing output on invalid $requestPort #46726

merged 1 commit into from
Apr 10, 2023

Conversation

eusonlito
Copy link
Contributor

@eusonlito eusonlito commented Apr 10, 2023

Laravel: 10.6.2
PHP: 8.1.17

On a docker deploy I get a random Undefined array key error when the server try to manage the Closing response on a undefined $requestPort.

The server command is:

php artisan serve --host=0.0.0.0 --port=80 >> storage/logs/artisan-serve.log 2>&1

Maybe the problem is getRequestPortFromLine parse, but for now maybe the best option is check the $this->requestsPool[$requestPort] value before continue with the output.

Screenshot from 2023-04-10 11-33-08

On a docker deploy I get a random `Undefined array key` when try to manage the `Closing` server response on a undefined `$requestPort`.

Maybe the problem is `getRequestPortFromLine` parse, but for now maybe the best option is check the `$this->requestsPool[$requestPort]` before continue with the output.
@eusonlito eusonlito changed the title [10.x] Fixed server Closing on invalid $requestPort [10.x] Fixed server Closing output on invalid $requestPort Apr 10, 2023
@taylorotwell taylorotwell merged commit 4d178bd into laravel:10.x Apr 10, 2023
@eusonlito
Copy link
Contributor Author

eusonlito commented Apr 11, 2023

@taylorotwell I have added a logger to src/Illuminate/Foundation/Console/ServeCommand.php and now I can see the problem.

Accepted event can be registered from multiple IPs on same port, but the ServeCommand is using only the port to manage the requests, then is trying to send the output of two different requests on same port as the same request.

[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

I think that the requestsPool key should be the IP and the port.

Regards!

@driesvints
Copy link
Member

@eusonlito what do you mean exactly? Should we revert this PR or...?

@eusonlito
Copy link
Contributor Author

@driesvints the previous (and current) version of $requestsPool is not handling requests as unique, since it is based only on the port, and not on the IP and port.

My patch is just to avoid the error when trying to close the same request twice.

Ideally, $requestPool should have the host and IP as a key to be able to handle each request uniquely.

I could send a PR to test this implementation.

@driesvints
Copy link
Member

Yes feel free to try a PR if you want 👍

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