Skip to content

Memory leak #179

@dmarkic

Description

@dmarkic

Hello,

When command is finished, it stays in memory as evenement/evenement events are still registered with command and so command is never destructed.

Version: 5.7.x
PHP Version: 7.4.33

A simple reproduction script:

$loop = \React\EventLoop\Loop::get();
$factory = new \React\MySQL\Factory();
$connection = $factory->createLazyConnection('localhost');

$loop->addPeriodicTimer(
    1,
    function () use ($connection) {
        $connection->query('SELECT \'' . str_repeat('A', 102400) . '\'')->done(
            function () {
                echo " - query done\n";
            },
            function ($e) {
                echo " - query error: " . $e->getMessage() . "\n";
            }
        );
        echo " - Memory usage: " . memory_get_usage() . "\n";
    }
);

$loop->run();

Example output:

 - Memory usage: 3563304
 - query done
 - Memory usage: 4415176
 - query done
 - Memory usage: 4638312
 - query done
 - Memory usage: 4861448
 - query done
 - Memory usage: 5084584
 - query done
 - Memory usage: 5307720
 - query done
 - Memory usage: 5530856
 - query done

I've made few changes to Io\Parser.php to call $command->removeAllListeners() in methods:

  • onError
  • onResultDone
  • onSuccess
  • onClose

It has solved the memory issue.

I think that's a major issue, should I create a simple PR where removeAllListeners() is called on command when it's finished?

Kind regards,
Dejan Markic

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy