grpc-java icon indicating copy to clipboard operation
grpc-java copied to clipboard

SafeMethodCachingInterceptor Half-closed without a request

Open Lengchuan opened this issue 2 years ago • 5 comments

SafeMethodCachingInterceptor.java

16:42:31.306 [grpc-nio-worker-ELG-1-2] DEBUG io.grpc.netty.shaded.io.grpc.netty.NettyClientHandler - [id: 0xa5392116, L:/10.173.96.176:59727 - R:/100.95.188.184:8090] INBOUND HEADERS: streamId=5 headers=GrpcHttp2ResponseHeaders[:status: 200, content-type: application/grpc, grpc-status: 13, grpc-message: Half-closed without a request, x-envoy-upstream-service-time: 5, date: Thu, 23 Jun 2022 08:42:31 GMT, server: istio-envoy] padding=0 endStream=true

My issue is that for every cached response I use, instead of reporting a grpc_client_status=OK I'm instead getting grpc_client_status=Internal with a message Half-closed without a request. I am assuming that this is coming from the server telling us that we started a call but then closed it early.

Is there a correct way to close out this request so that the server doesn't send us this error message? Right now my grpc client statistics make it look like an overwhelming number of our client requests are failing with an internal error, rather than succeeding.

Lengchuan avatar Jun 23 '22 09:06 Lengchuan

Is there a correct way to close out this request ...

Once the request is started and sent to the server, it has to include the expected request otherwise the server will respond with "half-closed" when prematurely half-closed like this.

The example client should be modified such that the delegate().start(...) is delayed. So this should be moved to just before super.sendMessage(message) on lines 263 and 288.

You may consider contributing a PR with this change if it works for you.

sanjaypujare avatar Jun 24 '22 03:06 sanjaypujare

I just realized there is another (simpler) way too: you can modify the request proto to make the actual request data optional and in case of a cache hit in sendMessage skip sending the actual request data but send the request to the server. And the server too will process the empty request and send an empty response (which is similarly modified to make the actual response data optional) thereby avoiding the "Half-closed without a request" error.

sanjaypujare avatar Jun 24 '22 15:06 sanjaypujare

Just briefly skimmed, but if we're talking about SafeMethodCachingInterceptor you will want to glance at https://groups.google.com/g/grpc-io/c/DIK6yHBJxEE/m/2jtCJkWAAQAJ

ejona86 avatar Jun 25 '22 02:06 ejona86

Looks like we can close this? Let us know if you have more questions/comments

sanjaypujare avatar Aug 25 '22 18:08 sanjaypujare

Leaving this open to fix the example, integrating some of that branch of mine and seeing if there is some other similar love that is needed to it.

ejona86 avatar Sep 27 '22 21:09 ejona86