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
24 changes: 13 additions & 11 deletions okhttp/src/main/java/io/grpc/okhttp/OkHttpServerTransport.java
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,19 @@ public void data(boolean inFinished, int streamId, BufferedSource in, int length
// concerned with the window being exceeded at this point.
in.require(length);

// connection window update
// The connection window must be updated even if the stream is in an errored state.
// See RFC 9113, section 6.9
connectionUnacknowledgedBytesRead += paddedLength;
if (connectionUnacknowledgedBytesRead
>= config.flowControlWindow * Utils.DEFAULT_WINDOW_UPDATE_RATIO) {
synchronized (lock) {
frameWriter.windowUpdate(0, connectionUnacknowledgedBytesRead);
frameWriter.flush();
}
connectionUnacknowledgedBytesRead = 0;
}

synchronized (lock) {
StreamState stream = streams.get(streamId);
if (stream == null) {
Expand All @@ -887,17 +900,6 @@ public void data(boolean inFinished, int streamId, BufferedSource in, int length
buf.write(in.getBuffer(), length);
stream.inboundDataReceived(buf, length, paddedLength - length, inFinished);
}

// connection window update
connectionUnacknowledgedBytesRead += paddedLength;
if (connectionUnacknowledgedBytesRead
>= config.flowControlWindow * Utils.DEFAULT_WINDOW_UPDATE_RATIO) {
synchronized (lock) {
frameWriter.windowUpdate(0, connectionUnacknowledgedBytesRead);
frameWriter.flush();
}
connectionUnacknowledgedBytesRead = 0;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,9 @@ public void windowUpdate() throws Exception {
writeDataDirectly(clientWriterSink, FLAG_PADDED | FLAG_END_STREAM, 1, message, 100);
clientFrameWriter.flush();
assertThat(clientFrameReader.nextFrame(clientFramesRead)).isTrue();
// Receive window update for the padded data size before stream reset
verify(clientFramesRead).windowUpdate(0, expectedConsumed + 100);
assertThat(clientFrameReader.nextFrame(clientFramesRead)).isTrue();
verify(clientFramesRead).rstStream(eq(1), eq(ErrorCode.FLOW_CONTROL_ERROR));
clientFrameWriter.rstStream(3, ErrorCode.CANCEL);
pingPong();
Expand Down
Loading