hyperium / tonic

A native gRPC client & server implementation with async/await support.
https://docs.rs/tonic
MIT License
9.76k stars 997 forks source link

How to detect disconnect on server and client sides? #1061

Closed crusader-mike closed 2 years ago

crusader-mike commented 2 years ago

(Not sure if it is the right place for this question, but I'll give it a try... If I am wrong -- direct me to proper venue, please.)

Suppose you have a server that performs a very long operation on behalf of the client (i.e. it's API has start(...) and stop(...) calls). Client invokes start() and then (probably 2 days later) stop() is invoked.

In case if client crashed (or someone cut network cable) I need to automatically call stop() on server side. http2-keep-alive feature can be used to break dead connection, but I couldn't figure out how to detect this situation.

Similarly on client side I need to be able to detect broken connection and reconnect (potentially followed by start()).

Is there a way to achieve this? Or I am inventing bicycles here and this problem is solved differently?

Edit: server needs to stop() only actions started by specific client (that is no longer alive).

LucioFranco commented 2 years ago

I would check in here to see if you have questions about disconnect https://github.com/hyperium/tonic/discussions?discussions_q=client+disconnect