Detect RPC connection loss from server-side on Windows - c++

Is there any way to check the status of the RPC connection from the server-side? I am looking for a way to detect if the connection from the client is lost, be it client crash or other connectivity issues.

Use Context Handles for managing server state between calls for a particular client. RPC uses keep-alive's to detect client disconnects and will execute your context handle rundown routine if the client disconnects.

Mo Flanagan's answer is the best IMHO. Some more context.
If you're using binding handles, there is no way of tracking state across RPC calls and the concept of a "client disconnect" is essentially meaningless - you still need to return from the RPC call.
If you're using context handles, then the RPC runtime library will call the _rundown function when the client disconnects.
When that routine is called, the server can clean up whatever it needs to.

Related

Apache Thrift: Terminate Connection from the Server

I am using thrift to provide an interface between a device and a management console. It is possible for there to be up to 4 active connections to the device at one time, and I have this working using a TThreadPool server.
The issue arises around client disconnections; If a client disconnects correctly, there is no issue, however if one does not (i.e. the client crashes out or doesn't call client->close()) then the server seems to keep that clients thread alive. This means that when the next connection attempt is made, the client hangs, as the server has used up its allocated thread pool so cannot service the new request.
I haven't been able to find any standard, public mechanism by which the server can stop, and hence free up, a clients thread if that client has not used the interface for a set time period?
Is there a standard way to facilitate this in thrift?
Set the receive/send timeout on the server socket might help. Server will close the connection on timeout.
https://github.com/apache/thrift/blob/129f332d72facda5d06f87e2b4e5e08bea0b6b44/lib/cpp/src/thrift/transport/TServerSocket.h#L103
void setSendTimeout(int sendTimeout);
void setRecvTimeout(int recvTimeout);

Tao Client robustness on server down

Context: In a server-client setup (using ace-tao).
Problem Statement: The server might be down, while the client is up and attempting to make API calls. Now to make the client setup more robust, I want to make the client to be able to know about the server-down-state, and when server is up again, it can attempt the rebind and get the new ORB ready, for any further API calls.
Any suggestions?
There is only one solution in case of TCP/IP. You must implement so-called heatbeat connection : simple echo connection and analyze the return code of read-write calls.
There is no callback in TCP/IP for connection state : alive or dead.

How to enable gRPC server to support just one client connection

I'm currently considering to use gRPC for basically inter-process communication between Java app (client) and C++ server. The RPC calls will use functionality from very old C++ code base which is definitely not thread-safe.
Normally the Java client will start more gRPC server instances and have just one connection with each server instance.
Is there any way how to ensure this on the gRPC server to accept just one connection and refuse all other attempts for connection. Otherwise I need to introduce some global lock in the RPC functions to have 100% correct server implementation.
There are plans to provide additional server side APIs that will allow the server to decide whether or not to accept an incoming connection, but this is not done yet. For now, a lock is probably a reasonable option.

CORBA : how does client poll from server?

I am a total newbie in CORBA. I have written a simple c++ CORBA CLIENT and a CORBA SERVER. I would like the client to ask a status from time to time from the server. However, I have no idea how to do that and my google searches give me no luck. Can anybody tell me how to perform polling of client to server? or perhaps how to catch notifications from server
The ability for a CORBA client to call/poll a method on a server is about as simple as CORBA development gets, and it's usually covered by the "Getting Started" section of an ORB's documentation. Here's a C++ Hello World example online for both a client and a server.
If you want the client to call the same method periodically, it's up to you as the client programmer to make that happen. You can put the client calling thread to sleep for some time between calls, set the client process to be launched on a regular basis by cron, whatever you prefer. CORBA won't initiate remote calls automatically for you. You have to instruct the CORBA layer to call the server on your behalf.
In addition to the answers above, you could also use the CORBA event or notification services to receive asynchronous notifications from a remote server to avoid polling.
And aside from polling, much more often client would provide object reference to one of its objects, and server would invoke a call on that object when something happens. That way polling could be completely avoided.

COM Server hang- detection and resolution

I have an application that sends requests to an out of proc COM server whom handles the requests and sends them back to the requesting application.
The client application is really in control of the start-stop of this Out-of-Proc COM server and determines its lifetime so to say.
Because this application has many hundreds of requests at any given time, it mostly has at least 4 of the same COM servers to handle these requests.
The problem is that sometimes this COM servers gets hung up handling a request, which is caught by the requesting application, whom kills the out of proc COM server. This however does not always happen.
What sometimes happens is that the client application requests a COM server kill, which results in the client releasing all references to the COM Server, but the COM server ends up just using 25% of the CPU and just never dies. It seems it just hangs and uses CPU constantly.
The client has mechanism to attempt to kill the COM Server process forcibly if it fails to die, however even that does not seem to work in the cases where the COM server gets into the CPU usage and just hangs.
Has anybody experienced something similar or has some advice on how one could resolve a situation like this?
You need to design all calls in the COM server in such way that they all end in some reasonably short time. Once a new call arrives from the client COM spawns a separate thread and dispatches a call onto that thread. There's no reliable way to interrupt the call - the call needs to end on itself (just return). You achieve this by designing your algorithm appropriately.