Skip to content

fix: Fixed an issue where BatchedSendQueue was including the HeadIndex twice when copying data, which was causing stream corruption when the data exceeded a certain throughput. [NCCBUG-187] #2332

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

Merged

Conversation

ShadauxCat
Copy link
Collaborator

@ShadauxCat ShadauxCat commented Dec 2, 2022

Changelog

  • Fixed: Fixed a case where data corruption could occur when using UnityTransport when reaching a certain level of send throughput.

Testing and Documentation

  • Includes unit test.
  • No documentation changes or additions were necessary.

…x twice when copying data, which was causing stream corruption when the data exceeded a certain throughput.
@ShadauxCat ShadauxCat requested a review from a team as a code owner December 2, 2022 23:14
@@ -226,7 +226,7 @@ public int FillWriterWithMessages(ref DataStreamWriter writer)
{
writer.WriteInt(messageLength);

var messageOffset = HeadIndex + reader.GetBytesRead();
var messageOffset = reader.GetBytesRead();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If you look above here, there's readerOffset = HeadIndex. This was changed in #2224 from readerOffset = 0 because reader was changed from being a slice of m_data to containing all of m_data and reading from that offset. The return value of GetBytesRead() here already includes HeadIndex, so this results in HeadIndex being applied twice when calculating messageOffset.

When HeadIndex is 0 that has no effect, but when the queue gets filled more, it starts resulting in things being skipped over, data being corrupted, and - sometimes - data from completely outside the stream (i.e., garbage data) being copied into the stream.

Copy link
Contributor

@simon-lemay-unity simon-lemay-unity left a comment

Choose a reason for hiding this comment

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

Great catch!

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

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

Just needs a changelog entry and it looks good to me!

@ShadauxCat ShadauxCat requested a review from a team as a code owner December 5, 2022 18:16
@ShadauxCat ShadauxCat merged commit 529419b into develop Dec 5, 2022
@ShadauxCat ShadauxCat deleted the fix/BatchedSendQueue_calculating_HeadIndex_twice branch December 5, 2022 21:19
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.

3 participants