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

Fix corrupt reads. #61

Merged
merged 2 commits into from Jun 15, 2016
Merged

Fix corrupt reads. #61

merged 2 commits into from Jun 15, 2016

Conversation

byrnedo
Copy link
Contributor

@byrnedo byrnedo commented Jun 15, 2016

Now continuously reads from stream in chunks until whole message is received.

Apparently fread stops when first packet is received, regardless if that's the whole message.

Now continuously reads from stream in chunks until whole message is received
@byrnedo byrnedo mentioned this pull request Jun 15, 2016
@coveralls
Copy link

coveralls commented Jun 15, 2016

Coverage Status

Coverage decreased (-5.1%) to 74.869% when pulling b0eac48 on byrnedo:develop into cbdff6b on repejota:develop.

@byrnedo
Copy link
Contributor Author

byrnedo commented Jun 15, 2016

I guess I need to add a test the reads a message with length.

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

Yeah ... if you can do it, would be awesome :)

@byrnedo
Copy link
Contributor Author

byrnedo commented Jun 15, 2016

Having a bit of trouble, don't quite get why $length is empty in receive in the tests :/

@repejota
Copy link
Owner

All the test suite is going to be refactored and probably rewritten, as you can see in #60.

Your problem may be due we are currently mocking all the NATS server but I'm moving everything to use a real NATS server thanks to Docker support on Travis.

If you have problems, no worries I can merge this without the proper test and I will add it once we use the real server 😉

@byrnedo
Copy link
Contributor Author

byrnedo commented Jun 15, 2016

Yeah, I've a feeling this will be fixed by sending via the real thing :)
I tried poking around but I think it's better I leave it until that is merged too!

@byrnedo
Copy link
Contributor Author

byrnedo commented Jun 15, 2016

Would be great to get this in ASAP since it's basically quite a breaking bug.

@repejota
Copy link
Owner

I will merge this tonight. 👍

@byrnedo
Copy link
Contributor Author

byrnedo commented Jun 15, 2016

sweet! :)

@coveralls
Copy link

coveralls commented Jun 15, 2016

Coverage Status

Coverage decreased (-6.3%) to 73.711% when pulling 851d881 on byrnedo:develop into cbdff6b on repejota:develop.

@repejota
Copy link
Owner

LGTM

@repejota repejota merged commit c12ae4d into repejota:develop Jun 15, 2016
@byrnedo
Copy link
Contributor Author

byrnedo commented Jun 16, 2016

Thanks @repejota :)

@dfeyer
Copy link
Contributor

dfeyer commented Jun 17, 2016

@byrnedo @repejota This one cause regression, if I store a JSON ... the last 2 byte are missing from the body :(

$receivedBytes += $chunkSize;
}
if (strlen($line) > 2) {
$line = substr($line, 0, -2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line create the regression, basically if there is escape char at the end of message, using rtrim is safer, but I'm not sure if the need to be done here. Maybe you should double check if you don't introduce those two bytes in your own code.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not at home but I will look at it ASAP. Thanks!

Copy link
Contributor Author

@byrnedo byrnedo Jun 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right that I don't need to trim those, I'm using protobuf on the wire and had a corrupt message initially when I didn't trim them but that must have been caused by something else I was doing.

Copy link
Contributor Author

@byrnedo byrnedo Jun 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had a look at the spec for MSG and the payload length doesn't include the \r\n at the end, from the example at http://nats.io/documentation/internals/nats-protocol/#a-name-msg-a-msg:4b9a176fc3df6b183e7b5ba0c60737ef.
I believe I added this line since initially I had incorrectly set if ( $bytesLeft < 1500 ) instead of the correct if ( $bytesLeft < $this->chunksize ), and that ended up reading in the \r\n at the end in cases.

Removing the substr section seems to work fine locally for me.

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

Successfully merging this pull request may close these issues.

None yet

4 participants