Hello @gjm
I'm not 100% sure that I understand your logic, but if I'm correctly you have a listener or something that logs events and during that logging perform actions where it retrievers more data that cause the infinite loop.
My advice should be to never load more data during the logging. You log the data that you have and on any other moment you can collect more data if needed.
It also lowers the amount of data that is logged.
Hello @tvbeek thanks for your help.
I have a custom User Provider that, among other things, logs successful and unsuccessful user retrieval.
When Auth::id()
is called for the first time the logged in user is retrieved from the database. Laravel Pail must have some listener to catch log calls and display them. The thing is this handler itself calls Auth::id()
to append the logged in user to the log info.
So, when Pail is trying to get the authenticated user to append to log message of the user retrieval it triggers another user retrieval, because the original one is still ongoing, which itself triggers another log entry and so on and so on until the memory limit is hit and the script aborts.
Hope I've made myself clear.
To be honest I don't have much hope on solving this... This would require a change in Pail or even in Laravel and I think I have too much of an edge case, since I'm using a custom provider, to have them make this change.
Thanks anyway.
Hello @gjm
I see that pail calls Auth::id()
and Auth::user()
here: https://github.com/laravel/pail/blob/main/src/Handler.php#L95-L96
There are a lot of packages that use the facades and will do multiple calls to the Auth::id()
or Auth::user()
. I also think that this will not be solved.
But honest question, what is the reason to write a log item in your retrieveById
function?
I should expect that you want to know if a login is successful or not. If that is the case I should log the Authentication events, see: https://laravel.com/docs/11.x/authentication#events
The code in the OP is very simplified. My user provider is actually layered, with database and LDAP directory records, and that is why I need to log success and (especially) failures.
But I agree with you... it's a tough cookie. Although I have the system in production for 3 years now and haven't had problems before.
Another question is, do you use pail? Else I should remove it and then you don't have the problem :)
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community