laravel / octane

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

Laravel Facades broken since Laravel 11.9.0 when using octane #915

Closed NiroDeveloper closed 3 months ago

NiroDeveloper commented 3 months ago

Octane Version

2.4.0

Laravel Version

11.9.0 - 11.11.0

PHP Version

8.3

What server type are you using?

Swoole

Server Version

5.1.3

Database Driver & Version

None

Description

I have notices that since Laravel 11.9.0 the Laravel Facades are broken in octane. I notices that because https://github.com/spatie/laravel-prometheus is not working anymore.

I am also able to reproduce this manually. The code is working with php fpm and apache, but not with octane and swoole. Problem is that octane resets the Facade before doing requests, so all variables in the Facade are lost.

I think this bug exists, because of this pull request: https://github.com/laravel/framework/pull/51343

Steps To Reproduce

ServiceProvider

public function register(): void
{
    $this->app->bind('test', fn() => new TestClass());
    Test::register();
}

TestClass - Register this Class as "Test"-Facade

class TestClass
{

    protected array $myData = [];

    public function register(): void
    {
        $this->myData[] = "My Data";
    }

    public function assert(): void
    {
        if (empty($this->myData)) {
            throw new InvalidStateException("You have to call register() first!");
        }
    }

}

RouteServiceProvider Route::any("/test", fn() => Test::assert());

crynobone commented 3 months ago

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

NiroDeveloper commented 3 months ago

@sarven You haven't tested your change with octane by any chance? https://github.com/laravel/framework/pull/51343 I'm trying to narrow down the cause further.

NiroDeveloper commented 3 months ago

I was able to verify that the bug was caused by the mentioned pull request. I have reverted the two changed functions locally and retested the problem.

I am still working on reproducing the problem in a new project, unfortunately I have an mistake in the classes I posted.

driesvints commented 3 months ago

@NiroDeveloper yeah we're really going to need a reproduction repo for this one. Please try to create one if you're able to.

sarven commented 3 months ago

@NiroDeveloper I haven't tested this with Octane. It was only checked by automatic tests, and manually on a fresh Laravel project just to verify performance impact. It was a simple change, so I'm waiting for the reproduction repository to see what's going on because I'm baffled that it could cause some problems.

NiroDeveloper commented 3 months ago

I think I have now understood my problem. It's not an Octane bug, so we could close this post.

For my case this mentioned pull request was just a breaking change. Now the getProvider function does not support inheritance of service providers. Should i create a issue in the laravel framework or is this a not foreseen feature in laravel? I can create a repo case, if you want to investigate further.

driesvints commented 3 months ago

I don't think we can support this use case sorry.