laravel / octane

Supercharge your Laravel application's performance.
https://laravel.com/docs/octane
MIT License
3.74k stars 291 forks source link

Throwing exception with FrankenPHP causes crash with 'Undefined array key "msg"' #803

Closed kohenkatz closed 8 months ago

kohenkatz commented 8 months ago

Octane Version

2.2.6

Laravel Version

10.28.0

PHP Version

8.2.7

What server type are you using?

FrankenPHP

Server Version

1.0.2

Database Driver & Version

No response

Description

The easiest way to reproduce this is to start the application without a .env file (or any other form of configuration). This will cause it to throw an Illuminate\Encryption\MissingAppKeyException.

Running php artisan octane:start starts the server, but produces the following error when trying to visit a page in the web browser:

   ErrorException 

  Undefined array key "msg"

  at vendor/laravel/octane/src/Commands/StartFrankenPhpCommand.php:271
    267▕             if (! is_array($debug = json_decode($output, true))) {
    268▕                 return $this->info($output);
    269▕             }
    270▕
  ➜ 271▕             if (is_array($stream = json_decode($debug['msg'], true))) {
    272▕                 return $this->handleStream($stream);
    273▕             }
    274▕
    275▕             if ($debug['msg'] == 'handled request') {

      +29 vendor frames 

  30  artisan:35
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

I added dump($debug); above that line, and here is the output that I get (before the same crash shown above):

array:11 [ // vendor/laravel/octane/src/Commands/StartFrankenPhpCommand.php:270
  "level" => "error"
  "ts" => 1704057667.2529
  "logger" => "http.log.access.log0"
  "msg" => "handled request"
  "request" => array:8 [
    "remote_ip" => "172.17.0.1"
    "remote_port" => "32878"
    "client_ip" => "172.17.0.1"
    "proto" => "HTTP/1.1"
    "method" => "GET"
    "host" => "127.0.0.1:8000"
    "uri" => "/"
    "headers" => array:15 [
      "Cookie" => []
      "Cache-Control" => array:1 [
        0 => "max-age=0"
      ]
      "Sec-Ch-Ua" => array:1 [
        0 => ""Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120""
      ]
      "Upgrade-Insecure-Requests" => array:1 [
        0 => "1"
      ]
      "Sec-Fetch-Mode" => array:1 [
        0 => "navigate"
      ]
      "Accept-Encoding" => array:1 [
        0 => "gzip, deflate, br"
      ]
      "Accept-Language" => array:1 [
        0 => "en-US,en;q=0.9,he-IL;q=0.8,he;q=0.7"
      ]
      "Connection" => array:1 [
        0 => "keep-alive"
      ]
      "Sec-Ch-Ua-Platform" => array:1 [
        0 => ""Windows""
      ]
      "Accept" => array:1 [
        0 => "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"     
      ]
      "Sec-Fetch-Dest" => array:1 [
        0 => "document"
      ]
      "User-Agent" => array:1 [
        0 => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
      ]
      "Sec-Fetch-User" => array:1 [
        0 => "?1"
      ]
      "Sec-Ch-Ua-Mobile" => array:1 [
        0 => "?0"
      ]
      "Sec-Fetch-Site" => array:1 [
        0 => "none"
      ]
    ]
  ]
  "bytes_read" => 0
  "user_id" => ""
  "duration" => 0.476934885
  "size" => 21
  "status" => 500
  "resp_headers" => array:6 [
    "Status" => array:1 [
      0 => "500 Internal Server Error"
    ]
    "Content-Type" => array:1 [
      0 => "text/plain;charset=UTF-8"
    ]
    "Cache-Control" => array:1 [
      0 => "no-cache, private"
    ]
    "Date" => array:1 [
      0 => "Sun, 31 Dec 2023 21:21:07 GMT"
    ]
    "Server" => array:1 [
      0 => "Caddy"
    ]
    "X-Powered-By" => array:1 [
      0 => "PHP/8.3.1"
    ]
  ]
]
array:7 [ // vendor/laravel/octane/src/Commands/StartFrankenPhpCommand.php:270
  "type" => "shutdown"
  "class" => "Illuminate\Encryption\MissingAppKeyException"
  "code" => 0
  "file" => "/srv/app/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php"
  "line" => 79
  "message" => "No application encryption key has been specified."
  "trace" => array:2 [
    0 => array:6 [
      "file" => "/srv/app/vendor/laravel/framework/src/Illuminate/Support/helpers.php"
      "line" => 307
      "function" => "Illuminate\Encryption\{closure}"
      "class" => "Illuminate\Encryption\EncryptionServiceProvider"
      "type" => "->"
      "args" => array:1 [
        0 => null
      ]
    ]
    1 => array:4 [
      "file" => "/srv/app/vendor/laravel/framework/src/Illuminate/Encryption/EncryptionServiceProvider.php"
      "line" => 77
      "function" => "tap"
      "args" => array:2 [
        0 => null
        1 => []
      ]
    ]
  ]
]

There is a msg in the first JSON body, but there is a message in the second one.

I would expect that the error is caught and displayed, not that the application would crash without showing the actual reason for the crash. (No error is logged in storage/logs/laravel.log either, as far as I can tell.

Steps To Reproduce

  1. Create a new Laravel application. Do NOT create a .env file.
  2. Install octane using FrankenPHP
  3. Run php artisan octane:start
  4. Navigate to the application in a web browser
driesvints commented 8 months ago

Thanks. I tried sending in a fix here: https://github.com/laravel/octane/pull/804

nunomaduro commented 8 months ago

Can't reproduce the issue. Can you create an open-source repository, with a fresh Laravel application + Octane, where it's easy to reproduce the issue locally for me? Please re-open the issue once you have that ready. Thanks!

DanielFortuyn commented 8 months ago

Fwiw, facing the same issue while moving an existing (old, but updated) laravel 10 project to frankenphp.

MaximeGratens commented 8 months ago

Same problem here. Can we open the issue ?

nunomaduro commented 8 months ago

I need a way to reproduce the issue. Can someone facing this issue helping with it?

MaximeGratens commented 8 months ago

For us, it's similar to Daniel's situation: it's a Laravel 10 project using PHP 8.3, and we migrated from RRR to FrankenPHP. We also don't have any .env file on our production server. However, it's working perfectly locally.

image

Here is the package and the version we used on this project

image
nunomaduro commented 8 months ago

Can you create an open-source repository, with a fresh Laravel installlation and Octane, where I can clone the repository locally to reproduce the issue?

kohenkatz commented 8 months ago

Can you create an open-source repository

I cannot work on this today or tomorrow, but I will see if I can do this on Sunday or Monday if no one else gets to it first.