From 68b4f42e7a00fd2c47ca1c9a84353ddf9c799373 Mon Sep 17 00:00:00 2001
From: deadEternally
Date: Sat, 1 Feb 2025 21:33:20 +0530
Subject: [PATCH 1/2] Changes
---
stub/src/main/java/io/grpc/stub/ClientCalls.java | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/stub/src/main/java/io/grpc/stub/ClientCalls.java b/stub/src/main/java/io/grpc/stub/ClientCalls.java
index 13fb00d3b3e..8f83670558d 100644
--- a/stub/src/main/java/io/grpc/stub/ClientCalls.java
+++ b/stub/src/main/java/io/grpc/stub/ClientCalls.java
@@ -100,6 +100,12 @@ public static void asyncServerStreamingCall(
* {@code beforeStart()} will be called.
*
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
+ * onError called on the request stream observer will result in stream cancellation. The response
+ * {@link StreamObserver} will be immediately notified of the cancellation with a
+ * {@link io.grpc.StatusRuntimeException}. The server's request stream observer will receive an
+ * onError callbackk from the gRPC server framework with a {@link io.grpc.StatusRuntimeException}
+ * for the cancellation. The actual exception passed by the client to onError is never actually
+ * transmitted to the server.
*/
public static StreamObserver asyncClientStreamingCall(
ClientCall call,
@@ -116,6 +122,12 @@ public static StreamObserver asyncClientStreamingCall(
* {@code beforeStart()} will be called.
*
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
+ * onError called on the request stream observer will result in stream cancellation. The response
+ * {@link StreamObserver} will be immediately notified of the cancellation with a
+ * {@link io.grpc.StatusRuntimeException}. The server's request stream observer will receive an
+ * onError callbackk from the gRPC server framework with a {@link io.grpc.StatusRuntimeException}
+ * for the cancellation. The actual exception passed by the client to onError is never actually
+ * transmitted to the server.
*/
public static StreamObserver asyncBidiStreamingCall(
ClientCall call, StreamObserver responseObserver) {
From 916e8487175bbadc8ff6d01dc55df1a769912a23 Mon Sep 17 00:00:00 2001
From: deadEternally
Date: Tue, 4 Feb 2025 14:08:29 +0530
Subject: [PATCH 2/2] Documenting error transmission and callback behavior.
---
.../main/java/io/grpc/stub/ClientCalls.java | 52 ++++++++++++++---
.../main/java/io/grpc/stub/ServerCalls.java | 58 +++++++++++++++++++
2 files changed, 102 insertions(+), 8 deletions(-)
diff --git a/stub/src/main/java/io/grpc/stub/ClientCalls.java b/stub/src/main/java/io/grpc/stub/ClientCalls.java
index 8f83670558d..194e37acd7a 100644
--- a/stub/src/main/java/io/grpc/stub/ClientCalls.java
+++ b/stub/src/main/java/io/grpc/stub/ClientCalls.java
@@ -70,6 +70,13 @@ private ClientCalls() {}
*
* If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
* {@code beforeStart()} will be called.
+ *
+ *
Server errors
+ * If the throwable sent to the server's outbound {@link StreamObserver}'s onError
+ * is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be
+ * received by the {@link ClientCall}'s onClose, and UNKNOWN status code otherwise. Its
+ * description will be encoded to the stream trailer, but the cause (which may contain server
+ * application's information) will not.
*/
public static void asyncUnaryCall(
ClientCall call, ReqT req, StreamObserver responseObserver) {
@@ -84,6 +91,13 @@ public static void asyncUnaryCall(
*
* If the provided {@code responseObserver} is an instance of {@link ClientResponseObserver},
* {@code beforeStart()} will be called.
+ *
+ *
Server errors
+ * If the throwable sent to the server's outbound {@link StreamObserver}'s onError
+ * is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be
+ * received by the {@link ClientCall}'s onClose, and UNKNOWN status code otherwise. Its
+ * description will be encoded to the stream trailer, but the cause (which may contain server
+ * application's information) will not.
*/
public static void asyncServerStreamingCall(
ClientCall call, ReqT req, StreamObserver responseObserver) {
@@ -100,12 +114,23 @@ public static void asyncServerStreamingCall(
* {@code beforeStart()} will be called.
*
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
+ *
+ * Client errors
* onError called on the request stream observer will result in stream cancellation. The response
* {@link StreamObserver} will be immediately notified of the cancellation with a
- * {@link io.grpc.StatusRuntimeException}. The server's request stream observer will receive an
- * onError callbackk from the gRPC server framework with a {@link io.grpc.StatusRuntimeException}
- * for the cancellation. The actual exception passed by the client to onError is never actually
- * transmitted to the server.
+ * {@link io.grpc.StatusRuntimeException} with the exception passed to onError set as the cause
+ * and the stream is considered closed. The server's request stream observer will receive an
+ * onError callback with a {@link io.grpc.StatusRuntimeException} for the cancellation with the
+ * message 'Client cancelled', and exception cause set to null because the actual exception
+ * passed by the client to onError is never actually transmitted to the server and the server
+ * just receives a RST_STREAM frame indicating cancellation by the client.
+ *
+ * Server errors
+ * If the throwable sent to the server's outbound {@link StreamObserver}'s onError
+ * is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be
+ * received by the {@link ClientCall}'s onClose, and UNKNOWN status code otherwise. Its
+ * description will be encoded to the stream trailer, but the cause (which may contain server
+ * application's information) will not.
*/
public static StreamObserver asyncClientStreamingCall(
ClientCall call,
@@ -122,12 +147,23 @@ public static StreamObserver asyncClientStreamingCall(
* {@code beforeStart()} will be called.
*
* @return request stream observer. It will extend {@link ClientCallStreamObserver}
+ *
+ * Client errors
* onError called on the request stream observer will result in stream cancellation. The response
* {@link StreamObserver} will be immediately notified of the cancellation with a
- * {@link io.grpc.StatusRuntimeException}. The server's request stream observer will receive an
- * onError callbackk from the gRPC server framework with a {@link io.grpc.StatusRuntimeException}
- * for the cancellation. The actual exception passed by the client to onError is never actually
- * transmitted to the server.
+ * {@link io.grpc.StatusRuntimeException} with the exception passed to onError set as the cause
+ * and the stream is considered closed. The server's request stream observer will receive an
+ * onError callback with a {@link io.grpc.StatusRuntimeException} for the cancellation with the
+ * message 'Client cancelled', and exception cause set to null because the actual exception
+ * passed by the client to onError is never actually transmitted to the server and the server
+ * just receives a RST_STREAM frame indicating cancellation by the client.
+ *
+ * Server errors
+ * If the throwable sent to the server's outbound {@link StreamObserver}'s onError
+ * is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be
+ * received by the {@link ClientCall}'s onClose, and UNKNOWN status code otherwise. Its
+ * description will be encoded to the stream trailer, but the cause (which may contain server
+ * application's information) will not.
*/
public static StreamObserver asyncBidiStreamingCall(
ClientCall call, StreamObserver responseObserver) {
diff --git a/stub/src/main/java/io/grpc/stub/ServerCalls.java b/stub/src/main/java/io/grpc/stub/ServerCalls.java
index 7990a5b34c0..b16bc396a04 100644
--- a/stub/src/main/java/io/grpc/stub/ServerCalls.java
+++ b/stub/src/main/java/io/grpc/stub/ServerCalls.java
@@ -26,6 +26,8 @@
import io.grpc.ServerCall;
import io.grpc.ServerCallHandler;
import io.grpc.Status;
+import io.grpc.StatusException;
+import io.grpc.StatusRuntimeException;
/**
* Utility functions for adapting {@link ServerCallHandler}s to application service implementation,
@@ -45,6 +47,14 @@ private ServerCalls() {
* Creates a {@link ServerCallHandler} for a unary call method of the service.
*
* @param method an adaptor to the actual method on the service implementation.
+ *
+ *
Server errors
+ * If the throwable sent to the server's outbound {@link StreamObserver}'s onError
+ * is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be sent
+ * and UNKNOWN status code otherwise. Its description will be encoded to the stream trailer, but
+ * the cause (which may contain server application's information) will not. After the stream
+ * trailer with END_STREAM is sent, the server side call is considered to be closed.
+ *
*/
public static ServerCallHandler asyncUnaryCall(
UnaryMethod method) {
@@ -55,6 +65,22 @@ public static ServerCallHandler asyncUnaryCall(
* Creates a {@link ServerCallHandler} for a server streaming method of the service.
*
* @param method an adaptor to the actual method on the service implementation.
+ *
+ *
Client errors
+ * The server's request stream observer will receive an
+ * onError callback with a {@link io.grpc.StatusRuntimeException} for the cancellation with the
+ * message 'Client cancelled', and exception cause set to null because the actual exception
+ * passed by the client to onError is never actually transmitted to the server and the server just
+ * receives a RST_STREAM frame indicating cancellation by the client.
+ *
+ *
+ *
Server errors
+ * If the throwable sent to the server's outbound {@link StreamObserver}'s onError
+ * is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be sent
+ * and UNKNOWN status code otherwise. Its description will be encoded to the stream trailer, but
+ * the cause (which may contain server application's information) will not. After the stream
+ * trailer with END_STREAM is sent, the server side call is considered to be closed.
+ *
*/
public static ServerCallHandler asyncServerStreamingCall(
ServerStreamingMethod method) {
@@ -65,6 +91,22 @@ public static ServerCallHandler asyncServerStreamingC
* Creates a {@link ServerCallHandler} for a client streaming method of the service.
*
* @param method an adaptor to the actual method on the service implementation.
+ *
+ *
Client errors
+ * The server's request stream observer will receive an
+ * onError callback with a {@link io.grpc.StatusRuntimeException} for the cancellation with the
+ * message 'Client cancelled', and exception cause set to null because the actual exception
+ * passed by the client to onError is never actually transmitted to the server and the server just
+ * receives a RST_STREAM frame indicating cancellation by the client.
+ *
+ *
+ *
Server errors
+ * If the throwable sent to the server's outbound {@link StreamObserver}'s onError
+ * is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be sent
+ * and UNKNOWN status code otherwise. Its description will be encoded to the stream trailer, but
+ * the cause (which may contain server application's information) will not. After the stream
+ * trailer with END_STREAM is sent, the server side call is considered to be closed.
+ *
*/
public static ServerCallHandler asyncClientStreamingCall(
ClientStreamingMethod method) {
@@ -75,6 +117,22 @@ public static ServerCallHandler asyncClientStreamingC
* Creates a {@link ServerCallHandler} for a bidi streaming method of the service.
*
* @param method an adaptor to the actual method on the service implementation.
+ *
+ *
Client errors
+ * The server's request stream observer will receive an
+ * onError callback with a {@link io.grpc.StatusRuntimeException} for the cancellation with the
+ * message 'Client cancelled', and exception cause set to null because the actual exception
+ * passed by the client to onError is never actually transmitted to the server and the server just
+ * receives a RST_STREAM frame indicating cancellation by the client.
+ *
+ *
+ *
Server errors
+ * If the throwable sent to the server's outbound {@link StreamObserver}'s onError
+ * is a {@link StatusException} or {@link StatusRuntimeException}, that status code will be sent
+ * and UNKNOWN status code otherwise. Its description will be encoded to the stream trailer, but
+ * the cause (which may contain server application's information) will not. After the stream
+ * trailer with END_STREAM is sent, the server side call is considered to be closed.
+ *
*/
public static ServerCallHandler asyncBidiStreamingCall(
BidiStreamingMethod method) {