[5.3] Using cached controller can lead to race conditions with middleware #14824
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Just ran into an issue with a recent change in 5.3 in which
Illuminate\Routing\Route::getController()
now caches it's result.Basically if you are running auth middleware via a group parameter in your routes file
and you use the
__construct()
method in your controller to bootstrap things that require auth in your controllerWhat you will see is that the Routing class will call
gatherMiddleware()
which will in turn callcontrollerMiddleware()
. ThatcontrollerMiddleware()
inits the controller class (to do reflection for any other middleware calls) before any route specified middleware is fired (the auth in this case) and caches the result.So when the example above happens,
$this->participant
isnull
because the auth middleware hasn't fired yet, logging the user in for that request.By removing the cache of
$this->controller
it allows the controller to be re-built after all the middleware is initiated and clears this bug up.It looks like the bug was unintentionally introduced in #14097 by @JosephSilber ... Joseph can you take a look at it and see if removing the cache causes any issues?