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.
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.
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.
...and the problem was that the internal buffer is not being reset/flushed when WriteByte is called when this buffer is already full.
| else if (_writePos == _bufferSize - 1) | ||
| else | ||
| { | ||
| FlushWrite(); |
There was a problem hiding this comment.
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 == _bufferSizeand in such case the next call to any of theWritemethods is supposed to flush the write buffer.