This example illustrates one way to free resources in a server that overrides the OnCancel method: https://github.com/grpc/grpc/blob/7017c09824b0806a69d2b62912a1dd830a057009/examples/cpp/route_guide/route_guide_callback_server.cc
You may benefit from reading the Callback API documentation, specifically the guarantees around when OnCancel and when OnDone must be called. https://github.com/grpc/proposal/blob/master/L67-cpp-callback-api.md Best, Adam On Thursday, July 27, 2023 at 5:12:57 AM UTC-7 Dmitry Gorelov wrote: > I found OnCancel() method in grpc::ServerWriteReactor and override it. > So now I get a notification when the client disconnects. > Unfortunatelly, there is no single example in grpc foler that could show > me how this function is to be used. > > The magor problem is, how to relesase the instance of > the grpc::ServerWriteReactor to free the resources, after the OnCancel() > triggered? > > If I delete the instance itself from the OnDone() callback, it works. > If I do the same from OnCancel, I get exceptions in grpc internal modules. > > Could you point me to the brief example how to delete the instance after > grpc::ServerWriteReactor::OnCancel() triggered? > > вторник, 25 июля 2023 г. в 16:54:00 UTC+3, Dmitry Gorelov: > >> Could you please help me to understand the subject? >> If no telegrams sent for some time, but connection is alive until the >> very moment when the client closed, >> how would the server detect that client dead without sending any grpc >> message to him? >> I use callback grpc api, v1.56 >> >> >> среда, 5 июля 2023 г. в 16:30:07 UTC+3, Dmitry Gorelov: >> >>> Hello, >>> Please help to setup the detection of the client disconnect on a server >>> side. >>> I use the document >>> https://github.com/grpc/grpc/blob/master/doc/keepalive.md >>> >>> *and my code on server side is:* >>> ... >>> ServerBuilder builder; >>> builder.AddListeningPort(server_address, >>> grpc::InsecureServerCredentials()); >>> builder.RegisterService(this); >>> builder.AddChannelArgument(GRPC_ARG_KEEPALIVE_TIME_MS, 30000); >>> builder.AddChannelArgument(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, 2000); >>> 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_MAX_PINGS_WITHOUT_DATA, 0); >>> builder.AddChannelArgument(GRPC_ARG_HTTP2_MAX_PING_STRIKES, 2); >>> builder.AddChannelArgument(GRPC_ARG_MAX_MESSAGE_LENGTH, 1024 * 1024 * >>> 8); >>> etc... >>> >>> *and on client side is:* >>> grpc::ChannelArguments args; >>> args.SetLoadBalancingPolicyName("round_robin"); >>> args.SetMaxReceiveMessageSize(MAX_RECEIVE_MESSAGE_SIZE); >>> args.SetMaxSendMessageSize(MAX_SEND_MESSAGE_SIZE); >>> args.SetInt(GRPC_ARG_KEEPALIVE_TIME_MS, 30000); >>> args.SetInt(GRPC_ARG_KEEPALIVE_TIMEOUT_MS, 2000); >>> args.SetInt(GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS, 1); >>> args.SetInt(GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA, 0); >>> m_channel = grpc::CreateCustomChannel(target, >>> grpc::InsecureChannelCredentials(), args); >>> auto ptr_stub = Rnd::NewStub(m_channel); >>> etc... >>> >>> But when the client application closes, nothing happens on the server >>> side. >>> It is built with gRPC Callback API. >>> >>> I also wondering what should I expect on a server side as an indication >>> of the fact that the client has disconnected... Any callback to overwrite? >>> Any server's property to check periodically? >>> >>> Thank you. >>> >> -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion visit https://groups.google.com/d/msgid/grpc-io/5a3f1c0d-81d3-4ebe-9c21-b2885c54246dn%40googlegroups.com.
