问题描述
我有一个使用grpc-java
库的gRPC服务器。有时,对服务器的调用会被关闭,错误状态为INTERNAL
,错误状态为13
,描述为Half-closed without a request
。
我发现另一个question似乎很相似,但是据说代码在调用onComplete()
之前先调用onNext()
,而我的端点实际上工作正常,就会发生此错误鉴于它会响应的呼叫数量非常零星。
看看UnaryServerCallListener
的实现,看来发生这种情况的唯一方法是,在request
上收到的onMessage
为空。
@Override
public void onMessage(ReqT request) {
if (this.request != null) {
// Safe to close the call,because the application has not yet been invoked
call.close(
Status.INTERNAL.withDescription(TOO_MANY_REQUESTS),new Metadata());
canInvoke = false;
return;
}
// We delay calling method.invoke() until onHalfClose() to make sure the client
// half-closes.
this.request = request;
}
@Override
public void onHalfClose() {
if (!canInvoke) {
return;
}
if (request == null) {
// Safe to close the call,because the application has not yet been invoked
call.close(
Status.INTERNAL.withDescription(MISSING_REQUEST),new Metadata());
return;
}
method.invoke(request,responseObserver);
request = null;
responseObserver.freeze();
if (wasReady) {
// Since we are calling invoke in halfClose we have missed the onReady
// event from the transport so recover it here.
onReady();
}
}
什么可能导致请求丢失?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)