Skip to content

Commit

Permalink
stub: avoid race in onHalfClose server StreamObserver
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-mastrangelo authored Jul 19, 2019
1 parent 8a9afd6 commit 148b7de
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion stub/src/main/java/io/grpc/stub/ServerCalls.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ private final class UnaryServerCallListener extends ServerCall.Listener<ReqT> {
private final ServerCall<ReqT, RespT> call;
private final ServerCallStreamObserverImpl<ReqT, RespT> responseObserver;
private boolean canInvoke = true;
private boolean wasReady;
private ReqT request;

// Non private to avoid synthetic class
Expand Down Expand Up @@ -171,7 +172,7 @@ public void onHalfClose() {
method.invoke(request, responseObserver);
request = null;
responseObserver.freeze();
if (call.isReady()) {
if (wasReady) {
// Since we are calling invoke in halfClose we have missed the onReady
// event from the transport so recover it here.
onReady();
Expand All @@ -188,6 +189,7 @@ public void onCancel() {

@Override
public void onReady() {
wasReady = true;
if (responseObserver.onReadyHandler != null) {
responseObserver.onReadyHandler.run();
}
Expand Down

0 comments on commit 148b7de

Please sign in to comment.