Skip to content

Commit

Permalink
Including an exception when cancelling the context when the status is…
Browse files Browse the repository at this point in the history
… not OK. Also take care to mark the call as cancelled only if the context has a cancellation cause.
  • Loading branch information
temawi committed Aug 12, 2021
1 parent c09379d commit 645ae56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/io/grpc/internal/ServerCallImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ private void closedInternal(Status status) {
} finally {
// Cancel context after delivering RPC closure notification to allow the application to
// clean up and update any state based on whether onComplete or onCancel was called.
// Note that in failure situations JumpToApplicationThreadServerStreamListener has already closed the context.
// In these situations this cancel() call will be a no-op.
// Note that in failure situations JumpToApplicationThreadServerStreamListener has already
// closed the context. In these situations this cancel() call will be a no-op.
context.cancel(null);
}
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/test/java/io/grpc/internal/ServerImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1196,15 +1196,17 @@ public void testStreamClose_clientOkTriggersDelayedCancellation() throws Excepti
context, contextCancelled, null);

// For close status OK:
// isCancelled is expected to be true after all pending work is done
// The context isCancelled is expected to be true after all pending work is done,
// but for the call it should be false as it gets set cancelled only if the call
// fails with a non-OK status.
assertFalse(callReference.get().isCancelled());
assertFalse(context.get().isCancelled());
streamListener.closed(Status.OK);
assertFalse(callReference.get().isCancelled());
assertFalse(context.get().isCancelled());

assertEquals(1, executor.runDueTasks());
assertTrue(callReference.get().isCancelled());
assertFalse(callReference.get().isCancelled());
assertTrue(context.get().isCancelled());
assertTrue(contextCancelled.get());
}
Expand Down

0 comments on commit 645ae56

Please sign in to comment.