okhttp: Remove finished stream even if a pending stream was started

Fixes #11053
This commit is contained in:
François JACQUES 2024-03-29 18:00:32 +01:00 committed by GitHub
parent 097a46b761
commit d21fe32bea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -953,8 +953,8 @@ class OkHttpClientTransport implements ConnectionClientTransport, TransportExcep
}
if (!startPendingStreams()) {
stopIfNecessary();
maybeClearInUse(stream);
}
maybeClearInUse(stream);
}
}
}

View File

@ -2080,6 +2080,26 @@ public class OkHttpClientTransportTest {
assertEquals(MISCARRIED, listener3.rpcProgress);
}
@Test
public void finishedStreamRemovedFromInUseState() throws Exception {
initTransport();
setMaxConcurrentStreams(1);
final MockStreamListener listener = new MockStreamListener();
OkHttpClientStream stream =
clientTransport.newStream(method, new Metadata(), CallOptions.DEFAULT, tracers);
stream.start(listener);
OkHttpClientStream pendingStream =
clientTransport.newStream(method, new Metadata(), CallOptions.DEFAULT, tracers);
pendingStream.start(listener);
waitForStreamPending(1);
clientTransport.finishStream(stream.transportState().id(), Status.OK, PROCESSED,
false, null, null);
verify(transportListener).transportInUse(true);
clientTransport.finishStream(pendingStream.transportState().id(), Status.OK, PROCESSED,
false, null, null);
verify(transportListener).transportInUse(false);
}
private int activeStreamCount() {
return clientTransport.getActiveStreams().length;
}