Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Call ProduceEnd() before consuming request body if response has already started (#1530) #1537

Merged
merged 2 commits into from
Mar 31, 2017

Conversation

cesarblum
Copy link
Contributor

@cesarblum cesarblum commented Mar 22, 2017

#1530

Prevents hanging clients waiting for the chunk terminator while server consumes the rest of the request body.

See https://github.com/dotnet/corefx/issues/17330#issuecomment-288248663.

cc @stephentoub

@davidfowl
Copy link
Member

@CesarBS can you rebase on top of @halter73 's change

Failed   Microsoft.AspNetCore.Server.Kestrel.FunctionalTests.AddressRegistrationTests.RegisterAddresses_IPv6ScopeId_Success(addressInput: "http://[fe80::1208:2b32:1916:e4b0%utun0]:0/", testUrls: Func`2 { Method = System.String[] GetTestUrls(Microsoft.AspNetCore.Hosting.Server.Features.IServerAddressesFeature), Target = null })

@@ -133,16 +133,28 @@ public Frame(IHttpApplication<TContext> application, ConnectionContext context)
{
ResumeStreams();

if (HasResponseStarted)
{
// If the response has already started, call ProduceEnd() before
Copy link
Member

Choose a reason for hiding this comment

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

Point to the bug in here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Pointed to the explanation in the corefx bug.

@cesarblum
Copy link
Contributor Author

@davidfowl Rebased.

await httpContext.Response.WriteAsync("hello, world");

// Force response start
await httpContext.Response.Body.FlushAsync();
Copy link
Member

Choose a reason for hiding this comment

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

You don't have to call FlushAsync to start the response, that happens on write

@davidfowl
Copy link
Member

Can you make sure we have a test for all of the relevant message body types? (Opaque, ContentLength, Chunked)

// If the expected behavior is regressed, this will hang because the
// server will try to consume the request body before flushing the chunked
// terminator.
await connection.Receive(
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 split this into two calls to connection.Receive() just to insert the above comment?

Copy link
Contributor Author

@cesarblum cesarblum Mar 22, 2017

Choose a reason for hiding this comment

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

No. It's to make it clear that the first part will be received fine, but if there's a regression the connection will time out waiting for the chunk terminator.

}

[Fact]
public async Task WhenResponseNotStartedResponseEndedAfterDrainingRequestBody()
Copy link
Member

Choose a reason for hiding this comment

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

Good test 👍

}

[Fact]
public async Task Sending100ContinueDoesNotStartResponse()
Copy link
Member

Choose a reason for hiding this comment

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

Can we test sending the chunk terminator pre-consume when we send a 100-continue and the app sends a response?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added.

@cesarblum
Copy link
Contributor Author

cesarblum commented Mar 30, 2017

Rebased.

@cesarblum
Copy link
Contributor Author

@davidfowl This is unrelated to the message body type, so having tests per type won't add value. What we care about here is the order in which things happen.

@cesarblum
Copy link
Contributor Author

📢

Copy link
Member

@davidfowl davidfowl left a comment

Choose a reason for hiding this comment

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

LGTM

@cesarblum cesarblum merged commit 6b9d542 into dev Mar 31, 2017
@cesarblum cesarblum deleted the cesarbs/1530 branch March 31, 2017 18:08
natemcmaster pushed a commit that referenced this pull request Apr 13, 2017
natemcmaster pushed a commit that referenced this pull request Apr 13, 2017
natemcmaster pushed a commit that referenced this pull request Apr 13, 2017
natemcmaster pushed a commit that referenced this pull request Apr 13, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants