ElephantIO / elephant.io

Send events to a socket.io server through PHP
https://elephantio.github.io/elephant.io/
MIT License
110 stars 34 forks source link

Endless running code during polling #27

Open Gared opened 2 days ago

Gared commented 2 days ago

I noticed that my code is running in an endless loop after calling this function:

$socketIoClient->wait('message', 2)

and this is the stack trace:

Decoder.php:79, ElephantIO\Parser\Polling\Decoder->__construct()
Polling.php:365, ElephantIO\Engine\Transport\Polling->recv()
SocketIO.php:349, ElephantIO\Engine\SocketIO->drain()
SocketIO.php:408, ElephantIO\Engine\SocketIO->waitForPacket()
SocketIO.php:341, ElephantIO\Engine\SocketIO->wait()
Client.php:133, ElephantIO\Client->wait()
...

In the Decoder->__construct method the code will execute the code

$len = (int) $seq->readUntil(':');

the method will return null, and $len has the value 0 in the end. After that this check happens:

if (null === $len) {
   throw new RuntimeException('Data delimiter not found!');
}

but $len is 0 so the exception will not be thrown and the code runs and runs and runs... My assumption is that the int-cast is wrong and should be removed here, but not sure:

$len = (int) $seq->readUntil(':');
tohenk commented 2 days ago

It seems related to packet decoding, can you post the full log?

Gared commented 15 hours ago

You mean the debug output with the requests and responses?