voryx / Thruway

PHP Client and Router Library for Autobahn and WAMP (Web Application Messaging Protocol) for Real-Time Application Messaging
MIT License
676 stars 117 forks source link

Memory leaks when we use Thruway as a synchronous client many times in one console command #315

Closed romansh closed 5 years ago

romansh commented 5 years ago

We are using Thruway as an asynchronous as well a synchronous client. In case of using a synchronous client we are facing a problem when memory leaks all the time. The following code is not from real project and does nothing useful (just open and close connection) but it can show the essence of the problem.

<?php
require_once('../../vendor/autoload.php');

use Thruway\ClientSession;
use Thruway\Connection;

while(1){
    usleep(10000);
    $connection = new Connection(["realm" => 'realm1', "url" => 'ws://127.0.0.1:8080/']);
    $connection->on('open', function (ClientSession $session) use ($connection) {
            $connection->close();
        }
    );
    $connection->open();

}

$connection = null; and unset($connection) don't help.

We are not using event and ev php extension, just default built-in php library. We are using php 7.2 inside of Ubuntu virtual mashine using Vagrant.

The problem above seems pretty similar to one for Ratchet described in https://github.com/ratchetphp/Ratchet/issues/662. I have tried it in hope it can help as Ratchet is under the hood of Thruway, but the proposed solution did not work.

romansh commented 5 years ago

Just tried to install event.so and run the script above. Memory leaks even faster.

mbonneau commented 5 years ago

@romansh Please checkout https://github.com/ratchetphp/Ratchet/issues/662 for more information on how to manage this issue.