Yii Framework Forum

Memory exhausted after creating new role


(Eafiontzi) #1

Hello,

We use yii2 for our custom CMS which runs authentication with RBAC. I have already about 5 roles for the backend login of our system. I created a new role with less permissions than the existing ones and when I tried to login with the user that had the new role assigned I got the following error:

Got error 'PHP message: PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 262144 bytes) in /home/backoffice/public_html/vendor/yiisoft/yii2/rbac/DbManager.php on line 158

I have increased the memory limit to 256 and also commented out the line of the error that was basically logging the error but the error still persists:

Got error 'PHP message: PHP Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 262144 bytes) in /home/backoffice/public_html/vendor/yiisoft/yii2/rbac/DbManager.php on line 160

Does anyone have any idea why this may be happening?
Thank you very much in advance,
Eleni


(Softark) #2

The most probable situation is that you have a loop in your RBAC hierarchy.
For example:

Permission A has Permission B as its child.
Permission B has Permission C as its child.
Permission C has Permission A as its child.

(Eafiontzi) #3

Thank you very much for the prompt reply! I already checked that but is not the case for two reasons

  • It works fine in the development environment and only throws the error in the live environment
  • The error is not in the recursive function of the DbManager but in the cache section

To my understanding the other existing roles are cached? Could something like that happen? Does the login procedure require so much resources to exhaust the system memory?

Thanks again.
Eleni


(Softark) #4

I see.
As far as I know, the change of the RBAC hierarchy is not automatically reflected in the cache. You have to invalidate the cache manually when you have changed the RBAC hierarchy.

[P.S.]
There exists a method called invalidateCache() in yii\rbac\DbManager.
https://www.yiiframework.com/doc/api/2.0/yii-rbac-dbmanager#invalidateCache()-detail
You can use it in your script (or migrations) for RBAC settings.

Does the login procedure require so much resources to exhaust the system memory?

I don’t think so. I believe almost all memory exhaustion come from an infinite loop.