Skip to content

Commit 804d9a2

Browse files
committed
flow control per stream
1 parent 3f54bfd commit 804d9a2

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

okhttp/src/main/java/io/grpc/okhttp/OkHttpClientStream.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,10 @@ public void deframeFailed(Throwable cause) {
281281
@Override
282282
@GuardedBy("lock")
283283
public void bytesRead(int processedBytes) {
284-
processedWindow -= processedBytes;
285284
if (processedWindow <= initialWindowSize * Utils.DEFAULT_WINDOW_UPDATE_RATIO) {
286285
int delta = initialWindowSize - processedWindow;
287-
window += delta;
288286
processedWindow += delta;
287+
window = initialWindowSize;
289288
frameWriter.windowUpdate(id(), delta);
290289
}
291290
}
@@ -321,11 +320,12 @@ public void transportHeadersReceived(List<Header> headers, boolean endOfStream)
321320
* Must be called with holding the transport lock.
322321
*/
323322
@GuardedBy("lock")
324-
public void transportDataReceived(okio.Buffer frame, boolean endOfStream) {
323+
public void transportDataReceived(okio.Buffer frame, boolean endOfStream, int paddingLen) {
325324
// We only support 16 KiB frames, and the max permitted in HTTP/2 is 16 MiB. This is verified
326325
// in OkHttp's Http2 deframer. In addition, this code is after the data has been read.
327326
int length = (int) frame.size();
328327
window -= length;
328+
processedWindow -= (length + paddingLen);
329329
if (window < 0) {
330330
frameWriter.rstStream(id(), ErrorCode.FLOW_CONTROL_ERROR);
331331
transport.finishStream(

okhttp/src/main/java/io/grpc/okhttp/OkHttpClientTransport.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,7 @@ public void data(boolean inFinished, int streamId, BufferedSource in, int length
11671167
synchronized (lock) {
11681168
// TODO(b/145386688): This access should be guarded by 'stream.transportState().lock';
11691169
// instead found: 'OkHttpClientTransport.this.lock'
1170-
stream.transportState().transportDataReceived(buf, inFinished);
1170+
stream.transportState().transportDataReceived(buf, inFinished, paddedLength - length);
11711171
}
11721172
}
11731173

okhttp/src/test/java/io/grpc/okhttp/OkHttpClientTransportTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,14 +792,14 @@ public void windowUpdate() throws Exception {
792792
frameHandler().data(false, 3, buffer, messageFrameLength, messageFrameLength);
793793

794794
verify(frameWriter, timeout(TIME_OUT_MS))
795-
.windowUpdate(eq(3), eq((long) 2 * messageFrameLength));
795+
.windowUpdate(eq(3), eq((long) 2 * messageFrameLength + paddingLength));
796796

797797
// Stream 2 receives another message
798798
buffer = createMessageFrame(fakeMessage);
799799
frameHandler().data(false, 5, buffer, messageFrameLength, messageFrameLength);
800800

801801
verify(frameWriter, timeout(TIME_OUT_MS))
802-
.windowUpdate(eq(5), eq((long) 2 * messageFrameLength));
802+
.windowUpdate(eq(5), eq((long) 2 * messageFrameLength + paddingLength));
803803
verify(frameWriter, timeout(TIME_OUT_MS))
804804
.windowUpdate(eq(0), eq((long) 2 * messageFrameLength));
805805

0 commit comments

Comments
 (0)