Search code examples
c#c++rpcthrift

How to detect server disconnection in Thrift?


Note: This similar question asks a different thing (detecting client disconnection on the server side).


I have a C# Thrift client connected over a named pipe transport to a C++ Thrift service. I would like to detect from the client when the C++ service dies, i.e. when the connection is no longer usable. I tried looking at the TTransport.IsOpen property, but it stays true no matter what. Is there a clean way to implement this (without extending my service with a heartbeat feature)?


Solution

  • To avoid dependency on the platform and even the chosen transport layer, I ended up adding a no-op ping call to my service. This is called periodically by the client from a background thread and does nothing on the server. The effect is that the IsOpen property of the pipe is updated and I also get an IOException when trying to call something. This is far from ideal but at least works and I was already wrapping my service for other reasons so I can hide this ugliness behind a nicer interface.