repejota / phpnats

A PHP client for the NATSio cloud messaging system.

Home Page:http://nats.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Randomly corrupt payload

byrnedo opened this issue · comments

I'm seeing that quite a high number of messages coming back from the same request are truncated somehow on the client side.

This happens randomly with the exact same message when sent repeatedly. Some work, some don't.

I debugged a little in the Connection::receive() function:

private function receive($len = null)
    {

        if ($len) {
            error_log("packet len [$len]");
            $line = fread($this->streamSocket, $len);
            error_log('line len [' . strlen($line) .']');
        } else {
            $line = fgets($this->streamSocket);
        }
        return $line;
    }

The output I get is:

PHP message: packet len [16236]
PHP message: line len [16236]
PHP message: packet len [16299]
PHP message: line len [16299]
PHP message: packet len [16258]
PHP message: line len [8658]

PHP message: line len [8658]

Is this something to do with the stream timeout?
I guess there are the following scenarios:

  1. Nats is reporting the wrong message length (packet len in the above)
  2. Fread is failing for some reason (time or otherwise)

Hi @byrnedo is this something urgent for you?
I'm working on adding docker support on our tests and deprecate our NATS server mockup on the tests as you can see at #60, that would help a lot on testing as we will use a real and latest NATS server.

Once i finish i will take a look on this ASAP.

Cheers!

Hi @repejota,

Actually, I think I have a fix :) It should be chunk reading the message when doing fread, I am testing the fix now so will be able to make a merge request shortly.

Nice! Thanks mate! 😄

See pull request #61

Closing after merging #61
Thanks @byrnedo !! 💪

No problem :)

But it is fixed right? If not I can reopen it an do some R&D 😉

It seems to work for me :) I was sending large-ish messages and it showed up. Small messages were fine, but all looks good now!

Shit, there was a bug, @repejota :( Check #64.