Prevent OnComplete modifying Streams

This commit is contained in:
Ben Adams 2015-12-15 04:46:05 +00:00
parent f5e45accac
commit 841ec73497
3 changed files with 31 additions and 0 deletions

View File

@ -91,6 +91,9 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
await FireOnStarting(); await FireOnStarting();
} }
_requestBody.PauseAcceptingReads();
_responseBody.PauseAcceptingWrites();
if (_onCompleted != null) if (_onCompleted != null)
{ {
await FireOnCompleted(); await FireOnCompleted();
@ -101,10 +104,12 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
// If _requestAbort is set, the connection has already been closed. // If _requestAbort is set, the connection has already been closed.
if (!_requestAborted) if (!_requestAborted)
{ {
_responseBody.ResumeAcceptingWrites();
await ProduceEnd(); await ProduceEnd();
if (_keepAlive) if (_keepAlive)
{ {
_requestBody.ResumeAcceptingReads();
// Finish reading the request body in case the app did not. // Finish reading the request body in case the app did not.
await messageBody.Consume(); await messageBody.Consume();
} }

View File

@ -123,6 +123,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
return this; return this;
} }
public void PauseAcceptingReads()
{
_state = StreamState.Closed;
}
public void ResumeAcceptingReads()
{
if (_state == StreamState.Closed)
{
_state = StreamState.Open;
}
}
public void StopAcceptingReads() public void StopAcceptingReads()
{ {
// Can't use dispose (or close) as can be disposed too early by user code // Can't use dispose (or close) as can be disposed too early by user code

View File

@ -89,6 +89,19 @@ namespace Microsoft.AspNet.Server.Kestrel.Http
return this; return this;
} }
public void PauseAcceptingWrites()
{
_state = StreamState.Closed;
}
public void ResumeAcceptingWrites()
{
if (_state == StreamState.Closed)
{
_state = StreamState.Open;
}
}
public void StopAcceptingWrites() public void StopAcceptingWrites()
{ {
// Can't use dispose (or close) as can be disposed too early by user code // Can't use dispose (or close) as can be disposed too early by user code