AtherEnergy / rumqtt

Pure rust mqtt cilent
The Unlicense
202 stars 71 forks source link

Graceful shutdown #135

Closed denizs closed 5 years ago

denizs commented 5 years ago

This PR introduces a new client method named shutdown, which allows the client to gracefully close the connection to the broker.

Implementation details:

The request_tx sends a Request::Disconnect. As a result, the handle_outgoing_disconnect method of the MqttState sets the MqttConnectionStatus to a new enum value named Disconnecting. To verfiy the client is currently disconnecting, MqttState now exposes a is_disconnecting method returning a bool.

This allows the mqtt event loop to verfiy, whether the NetworkError::NetworkStreamClosed error is actually expected to happen or not and jump out of the reconnect loop. For convenience, I pulled the should_reconnect_again function into the impl of the Connection, alleviating the necessity of passing in both, the reconnect opts and now also the is_diconnecting flag (as we don't want to be reconnected when we gracefully shutdown - even if our reconnect options state otherwise)

denizs commented 5 years ago

ping

tekjar commented 5 years ago

I've left some comments

denizs commented 5 years ago

I can't see them (yet) 😢

tekjar commented 5 years ago

Almost there. Few nits. We should be good to go after those changes :)

tekjar commented 5 years ago

I'll merge this and fix those :). Thanks for you contribution

denizs commented 5 years ago

Sorry - had somewhat of a stressful week! But thanks for taking over though 👍 Should I open another issue w.r.t. to the pause / resume issue so that we can discuss todos there?

tekjar commented 5 years ago

Sorry - had somewhat of a stressful week! But thanks for taking over though

Not a problem :)

Should I open another issue w.r.t. to the pause / resume issue so that we can discuss todos there?

Sure. That'll help