-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 the buffering bug that blocks SDK #51151
Conversation
Tagging subscribers to this area: @carlossanlop Issue DetailsI was able to identify the issue (after figuring out which process out of many should be debugged in the SDK repo): Write a failing test: And provide a fix; Some details: it's possible that
|
stream.WriteByte(0); | ||
writtenBytes.Add(0); | ||
|
||
byte[] bytes = new byte[BufferSize - 1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it worth putting something other than zeros in here? So it's distinct from the first byte you wrote
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't really matter. What matters is that we are attempting to write an 11th character on the stream when the buffer can only hold 10 characters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and the problem was that the internal buffer is not being reset/flushed when WriteByte is called when this buffer is already full.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @adamsitnik!
@@ -602,7 +602,7 @@ private void WriteByteSlow(byte value) | |||
ClearReadBufferBeforeWrite(); | |||
EnsureBufferAllocated(); | |||
} | |||
else if (_writePos == _bufferSize - 1) | |||
else | |||
{ | |||
FlushWrite(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this method should only be called when either _writePos == 0 or _writePos == _bufferSize, right?
Consider adding the assertion, but not in this PR since we want to merge it ASAP.
FlushWrite(); | |
Debug.Assert(_writePos == _bufferSize); | |
FlushWrite(); |
Fixes #51141
I was able to identify the issue (after figuring out which process out of many should be debugged in the SDK repo):
Write a failing test:
And provide a fix;
Some details: it's possible that
_writePos == _bufferSize
and in such case the next call to any of theWrite
methods is supposed to flush the write buffer.