yii2-debug
yii2-debug copied to clipboard
Debug toolbar memory leak
This issue has originally been reported by @djeux at https://github.com/yiisoft/yii2/issues/11419. Moved here by @cebe.
I'm building a queue system for Yii2 with beanstalkd. I've got a console controller to run in a loop checking for new jobs.
while ($run) {
$job = $queue->listen($tubeName);
if (null !== $job) {
try {
$job->handle();
} catch (Exception $e) {
$this->stderr($e->getMessage());
Yii::error($e->getMessage(), 'queue.' . $tubeName);
$job->release();
}
}
if ($this->isStopped() || $this->shouldRestart()) {
$run = false;
}
}
If I run it inside a loop I will constantly get increased memory usage (without handling any jobs). After cutting parts of the loop I found out that
$this-isStopped() and $this->shouldRestart()
Is causing it. The methods simply check for a key to be present inside cache (redis)
if (Yii::$app->cache->get(self::RESTART_CACHE_KEY)) {
$this->stdout("Restarting worker");
return true;
}
return false;
So just checking cache is taking more and more memory?
Yii 2.0.7
additional comments in https://github.com/yiisoft/yii2/issues/11419
It's not about debug. It's about logger overall.
well, no, normal logger will flush regualry, debug toolbar logger will not.
Normal loggers aren't flushing as well.
For normal loggers all messages are sent when exportInterval is reached: https://github.com/yiisoft/yii2/blob/master/framework/log/Target.php#L104 the only exception is debug toolbar, which overrides this method.
Has anyone found a solution to the problem? Is there another workaround than just turning off "YII_DEBUG"?
Thanks 👍
Do you have the problem in production environment?
I had similar issue. It is related to yii2-redis
source being polluted with log (\Yii::trace) entries, that can't be easily controlled:
- https://github.com/yiisoft/yii2-redis/blob/master/src/Connection.php#L543
- https://github.com/yiisoft/yii2-redis/blob/master/src/Connection.php#L673 (called for every cache operation)
- https://github.com/yiisoft/yii2-redis/blob/master/src/Connection.php#L577
Soo it is not really debuggers problem, to catch them by default.
Only solution would be to make debugger ignore debug messages by category yii\redis\Connection::executeCommand
, but there is no way to do that.
This could be solved by enhancing debugger with option to pass LogTarget
configuration via module config array.