Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

\Nats\Connection::handleMSG doesnt read trailing CR+LF #58

Open
VRciF opened this issue Jun 11, 2016 · 5 comments
Open

\Nats\Connection::handleMSG doesnt read trailing CR+LF #58

VRciF opened this issue Jun 11, 2016 · 5 comments
Assignees

Comments

@VRciF
Copy link

VRciF commented Jun 11, 2016

As the documentation states, a MSG has a CR+LF after the payload:
MSG [reply-to] <#bytes>\r\n[payload]\r\n

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!

@repejota repejota self-assigned this Jun 15, 2016
@byrnedo
Copy link
Contributor

byrnedo commented Jun 15, 2016

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

@repejota
Copy link
Owner

Amazing! 💪
Send me a PR and I will be happy to merge.

@repejota
Copy link
Owner

Closing as it is solved on #59
Thanks all! 😄

@byrnedo
Copy link
Contributor

byrnedo commented Jun 16, 2016

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.

@repejota
Copy link
Owner

Ok, I'm reopening this issue and i will try to look further.

@repejota repejota reopened this Jun 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants