\Nats\Connection::handleMSG doesnt read trailing CR+LF
As the documentation states, a MSG has a CR+LF after the payload:
MSG
The handleMSG method only reads the payload and leaves the trailing \r\n in the socket buffer. I understand that this is not much of a problem, because Connection::wait just ignores such empty lines, but in my case this behaviour causes a big problem.
I'm using nats as a platform to deliver messages TO and FROM a websocket connection. This means i use stream_socket_select to listen for incoming websocket messages and concurrently for incoming nats messages by abusing streamSocket which i extracted out of the Connection class using Reflection since streamSocket is private. Now the problem is, that since the newline is left in the buffer my stream_socket_select notices that a messages is waiting. Thus my call to wait(1) blocks indefinitely because it only reads those \r\n and waits for the message. This also means that my websocket connection is blocked.
So i would really appreciate it, if you could add something like $this->receive(2); in line 387 of \Nats\Connection to have correct protocol parsing. Many thanks in advance!
Hi @VRciF, I've discovered a bug when doing the fread call, where it doesn't correctly use a sensible chunk size. I've a fix in the works and have a feeling it will fix your issue too. See #59
Amazing! :muscle: Send me a PR and I will be happy to merge.
Closing as it is solved on #59 Thanks all! 😄
Hmm I'm not entirely sure that my fix for fread has solved this. The fread reads the whole message payload according to length in the header, presumably including the CR+LF. Then I strip the last 2 bytes.
So I guess that means the fget messages (whichever ones fall into that category) will not have those bytes read off the wire.
Ok, I'm reopening this issue and i will try to look further.