-
Notifications
You must be signed in to change notification settings - Fork 297
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
Controllers are not dropped per request #587
Comments
This should only be the case if your controller is registered as a singleton? Or you are injecting the container itself somehow? It is definitely not the case in Octane by default - which you can probably see if you try it on a fresh Laravel application using Breeze or something? |
The controller is not a singleton and I am just injecting the However I just tried your idea with a fresh Laravel application, with Octane installed and a simple invokable controller to return the dashboard. I added a logging into the constructor and the invokable method and this is the result. (the number is the spl object id) Here is the example app I created for showcasing it (changed logger to stderr) |
To show the problem I was talking about with Socialite factory, I have created a branch for replicating that issue. https://github.com/olivernybroe/octane-example/tree/socialite |
@taylorotwell I see your point about object id as it can in theory get the exact same memory location, however in my examples I posted I also did a log in the constructor and that is only happening once. I also just tried the example you shared here and I get the same value every time. Kapture.2022-09-30.at.08.40.33.mp4I did realise one difference and that is you were using RoadRunner, I just retried with RoadRunner and that does not reproduce my issue. So it seems like this is limited to Swoole actually. I just tried upgrading to Swoole 5 also, and the issue is still there. |
@olivernybroe Nuno and Taylor came up with a fix already which we're probably gonna tag somewhere today: |
@driesvints Ah cool! I just tried installing dev laravel and Nuno's branch with the fix for octane and it seems to solve it! 🎉 Thanks team ❤️ |
Fixed now, thanks! |
Description:
A controller will have the same instance throughout the whole lifetime of the application.
This doesn't sounds like a problem when first hearing it, the problem is when you start to do dependency injections via the constructor on a controller.
So we had a controller for handling socialite called
SocialiteController
, which tookLaravel\Socialite\Contracts\Factory
in through the constructor, in ourredirect
method we called$this->socialite->driver('someDriver')
and did the redirect.This would result in a
Target class [request] does not exist.
on the second request to this controller. Reason for this is that the Container instance on the SocialiteManager (the class that implements the factory) would point to the old app, and not the app for the new request, as the instance of the Manager is saved on the controller itself.This is not a problem with many other dependencies, as they do not depend on
request
, however SocialiteManager passed an instance of Request down to each driver.It looks like A workaround was created two years ago, in the class named
PrepareSocialiteForNextOperation
, however the following line always returnsfalse
, so the code for resetting the container and removing the old drivers never happens.octane/src/Listeners/PrepareSocialiteForNextOperation.php
Line 17 in 7ba4282
This issue seems to not be limited to
SocialiteManager
, but is something we also experienced withAuthManager
, resulting in people being logged in on others accounts.Our solution for unblocking us was to remove all of these dependencies into each controller method instead of having them shared at the constructor. However I feel that this might make sense to change, so all controllers are not stored in the application, but a new instance of the controller is created on every single request.
The text was updated successfully, but these errors were encountered: