Skip to content

blocking v2 client stub inconsistent about StatusRuntimeException verus StatusException #11937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
benjaminp opened this issue Mar 4, 2025 · 7 comments

Comments

@benjaminp
Copy link
Contributor

io.grpc.stub.BlockingClientCall uses the checked StatusException, so server-streaming and client-streaming v2 blocking RPCs have to deal with StatusException. However, the unary blocking v2 RPCs stubs have the implementation and thus behavior as v1; namely, all status exceptions are StatusRuntimeException. Should this be made consistent?

@kannanjgithub
Copy link
Contributor

The reason that we started using the checked exception is that we want to start moving in general to StatusException rather than StatusRuntimeException and the read/write methods in the BlockingClientCall already had other checked exceptions so it wasn't making things easier on the user if the status was unchecked.
ClientCalls and the old blocking stub are stable so we can't change from StatusRuntimeException to a checked exception even if we wanted to since we can't break existing code. The only way we could have the checked StatusException be thrown by unary blocking RPCs to to introduce new wrapper methods in BlockingClientCall that would catch and convert StatusRuntimeException to StatusException, however it doesn't appear like this is necessarily what you want.

@benjaminp
Copy link
Contributor Author

I'm just curious why this "blocking v2" interface is inconsistent. If the goal is to move to StatusException in general, why not make all blocking methods on the new interface throw the checked StatusException? Whether that requires adding new wrappers or not seems like an implementation detail.

@kannanjgithub
Copy link
Contributor

The commit that introduced BlockingClientCall was for creating blocking methods used by ClientCalls that is in turn used by the generated stub code (example).

Can you clarify what are the other blocking methods in the v2 interface you are referring to that don't throw StatusException?

@benjaminp
Copy link
Contributor Author

Can you clarify what are the other blocking methods in the v2 interface you are referring to that don't throw StatusException?

As the OP says, unary methods on the v2 interface use the same implementation as the v1 interface and therefore report errors with StatusRuntimeException.

@kannanjgithub
Copy link
Contributor

Figured you are asking not to make the already stable ClientCalls.blockingUnaryCall throw StatusException but why not make the new wrapper stub (this is what is v2)'s unaryRpc method catch and convert StatusRuntimeException to StatusException.

public static final class SimpleServiceBlockingV2Stub
      extends io.grpc.stub.AbstractBlockingStub<SimpleServiceBlockingV2Stub> {
  public io.grpc.testing.protobuf.SimpleResponse unaryRpc(io.grpc.testing.protobuf.SimpleRequest   request) {
      return io.grpc.stub.ClientCalls.blockingUnaryCall(
          getChannel(), getUnaryRpcMethod(), getCallOptions(), request);
  }
}

@kannanjgithub
Copy link
Contributor

We could make a new ClientCalls.blockingV2UnaryCall() that throws the checked StatusException.

@benjaminp
Copy link
Contributor Author

We could make a new ClientCalls.blockingV2UnaryCall() that throws the checked StatusException.

Makes sense to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants