Skip to content

Fix HttpResponseStreamWriter #19216

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
merged 2 commits into from
Feb 22, 2020
Merged

Fix HttpResponseStreamWriter #19216

merged 2 commits into from
Feb 22, 2020

Conversation

jkotalik
Copy link
Contributor

Fixes #18972. There was also another Debug.Assert being fired every time, so I changed WriteAsyncAwaited to WriteAsync to keep the invariant in tact.

@ghost ghost added the area-servers label Feb 21, 2020
@jkotalik jkotalik added this to the 5.0.0-preview2 milestone Feb 21, 2020
@@ -136,7 +136,7 @@ public override void Write(ReadOnlySpan<char> value)
}

var written = 0;
while (written < value.Length)
while (true)
Copy link
Member

Choose a reason for hiding this comment

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

I like keeping the terminating condition in the loop condition. Right now, it looks like written should be cumulative since it's defined outside of the loop, but really it's just that size of the last chunk that was written.

I would do var remaining = value.length; instead of var written = 0;, and then make while (remaining > 0) the loop condition. Then you can just put remaining -= written after var written = CopyToCharBuffer(value); and keep everything else the same as it was. I think that makes it much easier to see what's going on.

@@ -290,7 +292,6 @@ private async Task WriteAsyncAwaited(string value)
var count = value.Length;

Debug.Assert(count > 0);
Debug.Assert(_charBufferSize - _charBufferCount < count);
Copy link
Member

Choose a reason for hiding this comment

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

We can keep this assert now, right?

@jkotalik jkotalik merged commit ee8d843 into master Feb 22, 2020
@jkotalik jkotalik deleted the jkotalik/fixWrite branch February 22, 2020 00:16
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible bug in pull request #18451
3 participants