-
Notifications
You must be signed in to change notification settings - Fork 6
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
CborCodec
: bytes missing when decoding received messages
#6
Comments
CborCodec
: bytes missing when decoding received messages
Adding the return when we're prematurely reaching the end of the input data seems right, otherwise we would increase the offset of the buffer and look only at the second part of the data next time (which would be as "broken" as the first part). One would think that the offset should not increase when calling |
I am sorry for the late reply here. Thanks for reporting the issue.
You are right. We should not advance
How about the following unit test:
In case of an @sandreae would you mind creating a pull request with a fix and the above described unit test? Let me know in case you need any help. |
Ah great! Thanks for confirming, we will make a PR.
Yes, that's right, though I didn't mean the critical errors but the EOF "errors" aka |
Hi @mxinden, thanks for looking into this and the suggestions, it was a bit of a head-scratcher so I'm glad we got to the bottom of it. I can make a PR with the change and unit test in the next few days. |
Opened a PR here: #7 👍 |
With #7 merged, closing. here. Thank you for the help! |
We're using
CborCodec
in the handler for a custom network behaviour here and I'm observing some unexpected behaviour which I think is originating somewhere in this crate.The issue I'm seeing is that bytes encoded and sent from one peer don't arrive in their entirety on the receiving end. By adding logging to
decode
andencode
inCborCodec
I was able to observe more closely what is occurring.Peer A: logging from within
encode
onCborCodec
These bytes make up one complete message of our protocol, they're encoded on peer A and sent to Peer B.
Peer B: logging from within
decode
onCborCodec
These bytes arrive on peer B, they are roughly the first half of the bytes encoded above.
The next set of bytes arrive, these seem to be the final few bytes from the incomplete message bytes received above.
This occurs only sometimes, but has been observed on multiple systems. We wondered if it could be related to max buffer sizes being hit, but haven't been able to come up with a concrete theory here.
Solution attempts
Looking at
decode
onCborCodec
I wondered if the error handling was correct. If I add areturn
in the eof error case (as seen below) then the above issue doesn't occur anymore. But I'm not confident this is what was causing the issue or now we just hide the problem.Minimal reproducible example....
Unfortunately I don't have a simple example to share, If that's the only way to progress then I'm happy to create one, it's non-trivial work though so I'm opening this issue in case there is a something to be done already.
The text was updated successfully, but these errors were encountered: