Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ private enum ParsingState : byte
Done
}

public override bool NeedsDrain => (_connection != null);
public override bool NeedsDrain => CanReadFromConnection;

public override async ValueTask<bool> DrainAsync(int maxDrainBytes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private ReadOnlyMemory<byte> ReadFromConnectionBuffer(int maxBytesToRead)
return connectionBuffer.Slice(0, bytesToConsume);
}

public override bool NeedsDrain => (_connection != null);
public override bool NeedsDrain => CanReadFromConnection;

public override async ValueTask<bool> DrainAsync(int maxDrainBytes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ public HttpContentReadStream(HttpConnection connection) : base(connection)

protected bool IsDisposed => _disposed == 1;

protected bool CanReadFromConnection
{
get
{
// _connection == null typically means that we have finished reading the response.
// Cancellation may lead to a state where a disposed _connection is not null.
HttpConnection? connection = _connection;
return connection != null && connection._disposed != Status_Disposed;
}
}

public virtual ValueTask<bool> DrainAsync(int maxDrainBytes)
{
Debug.Fail($"DrainAsync should not be called for this response stream: {GetType()}");
Expand Down