Skip to content

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

Merged
merged 10 commits into from
Mar 19, 2019

Conversation

jkotalik
Copy link
Contributor

@jkotalik jkotalik commented Mar 6, 2019

For #8142

I still think I need #8198 to resolve this.

@jkotalik jkotalik requested review from davidfowl and Tratcher March 6, 2019 03:28
@jkotalik jkotalik added this to the 3.0.0-preview4 milestone Mar 6, 2019
@jkotalik jkotalik force-pushed the jkotalik/bufferRequestBody branch from f9fc8e2 to 21a57c8 Compare March 6, 2019 23:39
_context.Input.AdvanceTo(consumed, examined);

OnDataRead(dataLength);
var newlyExamined = examinedLength - _totalExaminedInPreviousReadResult;
if (newlyExamined > 0)
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Advance doesn't throw.

Copy link
Member

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.

@jkotalik
Copy link
Contributor Author

jkotalik commented Mar 8, 2019

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.

@jkotalik
Copy link
Contributor Author

jkotalik commented Mar 8, 2019

@aspnet/brt
[xUnit.net 00:01:21.57] E2ETests.PublishAndRunTests.PublishAndRun_Test(variant: Server: Kestrel, TFM: netcoreapp3.0, Type: Portable, Arch: x64) [FAIL]

Locked files...

@jkotalik
Copy link
Contributor Author

jkotalik commented Mar 8, 2019

@aspnet/brt

Microsoft (R) Test Execution Command Line Tool Version 16.0.0-preview-20190124-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
[xUnit.net 00:00:01.44]     Microsoft.AspNetCore.Identity.InMemory.Test.InMemoryStoreTest.ChangeEmailTokensFailsAfterEmailChanged [FAIL]
Failed   Microsoft.AspNetCore.Identity.InMemory.Test.InMemoryStoreTest.ChangeEmailTokensFailsAfterEmailChanged
Error Message:
 System.Security.Cryptography.CryptographicException : An error occurred while trying to encrypt the provided data. Refer to the inner exception for more information.
---- System.IO.IOException : The process cannot access the file '/home/helixbot/.aspnet/DataProtection-Keys/key-bd22c8d4-ce56-4de9-9cca-5fc1eeb7bc21.xml' because it is being used by another process.
Stack Trace:
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] plaintext) in /_/src/DataProtection/DataProtection/src/KeyManagement/KeyRingBasedDataProtector.cs:line 141
   at Microsoft.AspNetCore.Identity.DataProtectorTokenProvider`1.GenerateAsync(String purpose, UserManager`1 manager, TUser user) in /_/src/Identity/Core/src/DataProtectorTokenProvider.cs:line 86
   at Microsoft.AspNetCore.Identity.Test.UserManagerSpecificationTestBase`2.ChangeEmailTokensFailsAfterEmailChanged() in /_/src/Identity/Specification.Tests/src/UserManagerSpecificationTests.cs:line 1761
--- End of stack trace from previous location where exception was thrown ---
----- Inner Stack Trace -----
   at System.IO.FileStream.Init(FileMode mode, FileShare share, String originalPath)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
   at System.IO.File.OpenRead(String path)
   at Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.ReadElementFromFile(String fullPath) in /_/src/DataProtection/DataProtection/src/Repositories/FileSystemXmlRepository.cs:line 102
   at Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.GetAllElementsCore()+MoveNext() in /_/src/DataProtection/DataProtection/src/Repositories/FileSystemXmlRepository.cs:line 83
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository.GetAllElements() in /_/src/DataProtection/DataProtection/src/Repositories/FileSystemXmlRepository.cs:line 68
   at Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager.GetAllKeys() in /_/src/DataProtection/DataProtection/src/KeyManagement/XmlKeyManager.cs:line 152
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.CreateCacheableKeyRingCore(DateTimeOffset now, IKey keyJustAdded) in /_/src/DataProtection/DataProtection/src/KeyManagement/KeyRingProvider.cs:line 57
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.Microsoft.AspNetCore.DataProtection.KeyManagement.Internal.ICacheableKeyRingProvider.GetCacheableKeyRing(DateTimeOffset now) in /_/src/DataProtection/DataProtection/src/KeyManagement/KeyRingProvider.cs:line 254
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRingCore(DateTime utcNow) in /_/src/DataProtection/DataProtection/src/KeyManagement/KeyRingProvider.cs:line 186
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingProvider.GetCurrentKeyRing() in /_/src/DataProtection/DataProtection/src/KeyManagement/KeyRingProvider.cs:line 142
   at Microsoft.AspNetCore.DataProtection.KeyManagement.KeyRingBasedDataProtector.Protect(Byte[] plaintext) in /_/src/DataProtection/DataProtection/src/KeyManagement/KeyRingBasedDataProtector.cs:line 102
Results File: /home/helixbot/dotnetbuild/work/b32e663f-b42f-40af-be42-bd070ee33b2a/Work/b35bd579-11f7-4641-93d6-5e8831a65951/Exec/TestResults/_dnfed28op000AZM_2019-03-08_11_08_50_913.trx

@jkotalik jkotalik marked this pull request as ready for review March 8, 2019 22:21
@jkotalik jkotalik closed this Mar 12, 2019
@jkotalik jkotalik reopened this Mar 12, 2019
@jkotalik jkotalik force-pushed the jkotalik/bufferRequestBody branch from 3f3a591 to 2cdb6da Compare March 12, 2019 18:07
@jkotalik
Copy link
Contributor Author

@halter73 @davidfowl same with this one

@jkotalik jkotalik requested a review from halter73 March 13, 2019 04:40

if (_readCompleted)
{
_readResult = new ReadResult(_readResult.Buffer.Slice(consumed, _readResult.Buffer.End), isCanceled: false, _readCompleted);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_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);

Copy link
Member

@halter73 halter73 left a 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.

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);
Copy link
Member

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?

Copy link
Member

@halter73 halter73 left a 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.

@jkotalik jkotalik force-pushed the jkotalik/bufferRequestBody branch from ec3fd76 to 14af05d Compare March 18, 2019 20:44
@jkotalik jkotalik merged commit 26c487b into master Mar 19, 2019
@jkotalik jkotalik deleted the jkotalik/bufferRequestBody branch March 19, 2019 15:26
@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Jun 6, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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.

8 participants