planetteamspeak / ts3phpframework

Modern use-at-will framework that provides individual components to manage TeamSpeak 3 Server instances
https://www.planetteamspeak.com
GNU General Public License v3.0
211 stars 59 forks source link

OOM Issue (StringHelper.php:211) on PHP 8.2 / TS 3.13 #216

Open M4LuZ opened 6 months ago

M4LuZ commented 6 months ago

Hi y'all,

I'm currently working on a refresh of the integration of ts3phpframework into the LanSuite Lanparty CMS . I'm facing an apparent regression between 1.1.35 and 1.2.1 causing an out-of-memory error ultimately thrown in StringHelper.php Line 211

Story so far

I saw that this issue was apparently already noticed and supposed to be fixed in #195 but somehow this appears not to be the case? So would be greatly appreciated to get some feedback on that.

Environment

M4LuZ commented 6 months ago

Did a bit of tracing on dev-dev and it turns out that the memory leak is in the Transport destructor.

Apparently while waitForReadyRead in Transport.php is supposed to immediately return when disconnected or in blocking mode it goes through the do {...} while(@stream_select(...)) loop indefinitely. Adding blocking=0 to the query string appears to break the loop, timeout does not.

2024-04-10 21_58_14-WinCacheGrind -  C__xampp_htdocs_lansuite_index php (cachegrind out 12668)
toster234 commented 4 months ago

I moved $this->disconnect(); in Transport.php destructor and the issue seems to be fixed?

    public function __destruct()
    {
+       $this->disconnect();
        if ($this->adapter instanceof Adapter) {
            $this->adapter->__destruct();
        }
-
-        $this->disconnect();
    }
M4LuZ commented 3 months ago

Hi @toster234 ,

sorry for the late reply. Can confirm that this solves the issue for me. A quick check with the text viewer worked OK (the other two HTML / JSON appear to be broken and are the next ticket to be raised).