How I handle client disconnects is by using a callback on the RPC method and utilize the context to keep track of which client it is.
class Service(ServiceServicer):
def context_callback(self, context: grpc.ServicerContext):
def callback():
# Cleanup code here
cleanup_with_context(context)
return callback
def DoJob(self, work_pb: Work, context: grpc.ServicerContext):
context.add_callback(self.context_callback(context))
# Job code here.
Not sure this is the 100% way to do it but this is how I'm able to do it.