简体   繁体   English

为 C++ gRPC 异步服务器中的丢失连接提供什么通知

[英]What notification is provided for a lost connection in a C++ gRPC async server

I have an async gRPC server for Windows written in C++.我有一个用于 Windows 的异步 gRPC 服务器,用 C++ 编写。 I'd like to detect the loss of connection to a client – whether a network connection is lost, or the client crashes, etc. I see references to the keepalive channel arguments, and I've tried various combinations of those settings, such as:我想检测与客户端的连接丢失 - 无论是网络连接丢失还是客户端崩溃等。我看到对 keepalive 通道 arguments 的引用,我尝试了这些设置的各种组合,例如:

builder.AddChannelArgument(GRPC_ARG_KEEPALIVE_TIME_MS, 10000);
builder.AddChannelArgument(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, 10000);
builder.AddChannelArgument(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1);
builder.AddChannelArgument(GRPC_ARG_HTTP2_MIN_RECV_PING_INTERVAL_WITHOUT_DATA_MS, 9000);
builder.AddChannelArgument(GRPC_ARG_HTTP2_BDP_PROBE, 1);

I've done some testing with a streaming RPC method.我已经使用流式 RPC 方法进行了一些测试。 If I kill the client process and then try to send data to the client, the lost connection is detected.如果我终止客户端进程然后尝试向客户端发送数据,则会检测到丢失的连接。 I don't actually even have to send data.我实际上什至不必发送数据。 I can set an Alarm object to trigger immediately and that causes the call handler to be cancelled.我可以设置警报 object 立即触发,这会导致调用处理程序被取消。 However, if I don't try to send data (or set an alarm) after killing the client process then there's no notification or callback that I've been able to find/enable.但是,如果我在终止客户端进程后不尝试发送数据(或设置警报),那么就没有我能够找到/启用的通知或回调。 I must not have a complete understanding.我一定没有完全了解。 So:所以:

  1. How does the detection of a lost connection manifest itself for the server?检测到丢失的连接如何体现在服务器上? Is there a callback method, or notification of some type?是否有回调方法或某种类型的通知? My server doesn't receive any errors;我的服务器没有收到任何错误; the completion queue's 'Next()' method never returns, etc.完成队列的 'Next()' 方法永远不会返回,等等。
  2. Does this detection work for both unary (call/response) and streaming methods?此检测是否适用于一元(呼叫/响应)和流式方法?
  3. Does the server detection of a lost connection work whether or not the client has implemented lost connection / keepalive logic?无论客户端是否实现了丢失连接/保持活动逻辑,服务器检测丢失的连接是否有效?
  4. Is there some method besides the keepalive channel arguments that is preferred?除了keepalive通道arguments之外还有什么方法是首选的吗?

Thanks - any help is appreciated.谢谢 - 任何帮助表示赞赏。

You can use ServerContext::AsyncNotifyWhenDone() to get a notification when the request has been cancelled.您可以使用ServerContext::AsyncNotifyWhenDone()在请求被取消时获取通知。

https://grpc.github.io/grpc/cpp/classgrpc__impl_1_1_server_context_base.html#a0f1289f31257e6dbef57bc901bd7b5f2 https://grpc.github.io/grpc/cpp/classgrpc__impl_1_1_server_context_base.html#a0f1289f31257e6dbef57bc901bd7b5f2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM