-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Use examined rather than consumed for content length of body. #8223
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
Conversation
src/Servers/Kestrel/Core/src/Internal/Http/Http1ContentLengthMessageBody.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http/Http1ContentLengthMessageBody.cs
Outdated
Show resolved
Hide resolved
f9fc8e2
to
21a57c8
Compare
src/Servers/Kestrel/Core/src/Internal/Http/Http1ContentLengthMessageBody.cs
Outdated
Show resolved
Hide resolved
_context.Input.AdvanceTo(consumed, examined); | ||
|
||
OnDataRead(dataLength); | ||
var newlyExamined = examinedLength - _totalExaminedInPreviousReadResult; | ||
if (newlyExamined > 0) |
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.
Did you confirm if examined can go backwards? Or does Advance throw?
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.
Advance doesn't throw.
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.
Examined can't go backwards.
Current test failures are due to how we now handle Read/Advance combinations. If we reached the end of content, we make ReadAsync return immediately with the current ReadResult, even if the user didn't call advance. I can fix this by adding a bool that flips each time read/advance is called, but I don't think it's a huge deal. It's inconsistent with how pipes work, but IMO isn't a big deal. I'll add a bool for now and let you all decide how it looks. |
@aspnet/brt Locked files... |
@aspnet/brt
|
3f3a591
to
2cdb6da
Compare
@halter73 @davidfowl same with this one |
|
||
if (_readCompleted) | ||
{ | ||
_readResult = new ReadResult(_readResult.Buffer.Slice(consumed, _readResult.Buffer.End), isCanceled: false, _readCompleted); |
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.
_readResult = new ReadResult(_readResult.Buffer.Slice(consumed, _readResult.Buffer.End), isCanceled: false, _readCompleted); | |
_readResult = new ReadResult(_readResult.Buffer.Slice(consumed, _readResult.Buffer.End), Interlocked.Exchange(ref _userCanceled, 0) == 1, _readCompleted); |
src/Servers/Kestrel/Core/src/Internal/Http/Http1ContentLengthMessageBody.cs
Outdated
Show resolved
Hide resolved
src/Servers/Kestrel/Core/src/Internal/Http/Http1ContentLengthMessageBody.cs
Outdated
Show resolved
Hide resolved
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.
I'm mostly concerned about the _finalAdvanceAfterReadingEntireContentLength AdvanceTo logic.
src/Servers/Kestrel/Core/src/Internal/Http/Http1ContentLengthMessageBody.cs
Show resolved
Hide resolved
Assert.Equal(5, readResult.Buffer.Length); | ||
httpContext.Request.BodyReader.AdvanceTo(readResult.Buffer.Start, readResult.Buffer.End); | ||
readResult = await httpContext.Request.BodyReader.ReadAsync(); | ||
Assert.Equal(5, readResult.Buffer.Length); |
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.
Do you have any tests that attempt more than one read after getting a completed read result?
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.
If you don't have any tests that attempt more than one read after observing a completed read result, add one.
ec3fd76
to
14af05d
Compare
For #8142
I still think I need #8198 to resolve this.