Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -198,6 +198,14 @@ private async Task WriteToOutputPipe()
// Now check the connection window
actual = CheckConnectionWindow(actual);

// actual is negative means window size has become negative
// this can usually happen if the receiver decreases window size before receiving the previous data frame
// in this case, reset to 0 and continue, no data will be sent but will wait for window update
if (actual < 0)
{
actual = 0;
}

// Write what we can
if (actual < buffer.Length)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4751,6 +4751,52 @@ await ExpectAsync(Http2FrameType.DATA,
Assert.True(_helloWorldBytes.AsSpan(9, 3).SequenceEqual(dataFrame3.PayloadSequence.ToArray()));
}

[Fact]
public async Task WINDOW_UPDATE_Received_OnStream_Resumed_WhenInitialWindowSizeNegativeMidStream()
{
const int windowSize = 3;
_clientSettings.InitialWindowSize = windowSize;
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
await InitializeConnectionAsync(async context =>
{
var bodyControlFeature = context.Features.Get<IHttpBodyControlFeature>();
bodyControlFeature.AllowSynchronousIO = true;
await context.Response.Body.WriteAsync(new byte[windowSize - 1], 0, windowSize - 1);
await tcs.Task;
await context.Response.Body.WriteAsync(new byte[windowSize], 0, windowSize);
});
await StartStreamAsync(1, _browserRequestHeaders, endStream: true);
await ExpectAsync(Http2FrameType.HEADERS,
withLength: 32,
withFlags: (byte)Http2HeadersFrameFlags.END_HEADERS,
withStreamId: 1);

// Decrease window size after server has already sent the current window - 1 size of data
_clientSettings.InitialWindowSize = windowSize - 2;
await SendSettingsAsync();
await ExpectAsync(Http2FrameType.DATA,
withLength: windowSize - 1,
withFlags: (byte)Http2DataFrameFlags.NONE,
withStreamId: 1);
await ExpectAsync(Http2FrameType.SETTINGS,
withLength: 0,
withFlags: (byte)Http2DataFrameFlags.END_STREAM,
withStreamId: 0);
tcs.SetResult();

// send window update to receive the next frame data
await SendWindowUpdateAsync(1, windowSize + 1);
await ExpectAsync(Http2FrameType.DATA,
withLength: windowSize,
withFlags: (byte)Http2DataFrameFlags.NONE,
withStreamId: 1);
await ExpectAsync(Http2FrameType.DATA,
withLength: 0,
withFlags: (byte)Http2DataFrameFlags.END_STREAM,
withStreamId: 1);
await StopConnectionAsync(expectedLastStreamId: 1, ignoreNonGoAwayFrames: false);
}

[Fact]
public async Task CONTINUATION_Received_Decoded()
{
Expand Down
Loading