yii2-debug icon indicating copy to clipboard operation
yii2-debug copied to clipboard

Debug toolbar memory leak

Open yii-bot opened this issue 8 years ago • 8 comments

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

yii-bot avatar Apr 27 '16 13:04 yii-bot

additional comments in https://github.com/yiisoft/yii2/issues/11419

cebe avatar Apr 27 '16 13:04 cebe

It's not about debug. It's about logger overall.

samdark avatar Apr 27 '16 16:04 samdark

well, no, normal logger will flush regualry, debug toolbar logger will not.

cebe avatar Apr 27 '16 21:04 cebe

Normal loggers aren't flushing as well.

samdark avatar Apr 27 '16 22:04 samdark

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.

cebe avatar Apr 28 '16 02:04 cebe

Has anyone found a solution to the problem? Is there another workaround than just turning off "YII_DEBUG"?

Thanks 👍

ghost avatar Nov 21 '17 15:11 ghost

Do you have the problem in production environment?

samdark avatar Nov 23 '17 06:11 samdark

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.

Deele avatar May 17 '18 03:05 Deele