dotnet / MQTTnet

MQTTnet is a high performance .NET library for MQTT based communication. It provides a MQTT client and a MQTT server (broker). The implementation is based on the documentation from http://mqtt.org/.
MIT License
4.51k stars 1.07k forks source link

Disconnect behavior throws exception on worker thread #887

Closed LADSoft closed 4 years ago

LADSoft commented 4 years ago

we have a bug in our app where we aren't passing messages through to a broken and back properly, so we time out. We are the client, using MqttNet. On a timeout we attempt to close the client (via _client.DisconnectAsync()) and then we dispose it. Some time later the app crashes with an exception on a worker thread, related to the fact that when MqttNet closes a socket it might get an 'object disposed' exception from system worker threads related to when the socket was previously open. Here is what stack overflow says about having to explicitly deal with this issue:

https://stackoverflow.com/questions/37135733/after-disposing-async-socket-net-callbacks-still-get-called

chkr1011 commented 4 years ago

This is a known issue. It is hard to fix (as you can see in the stackoverflow post). Please try the upcoming 3.0.9-rc2. We made some changes in order to catch those exceptions.

SeppPenner commented 4 years ago

@LADSoft Would you consider this as fixed now?

LADSoft commented 4 years ago

will check it out tomorrow.

LADSoft commented 4 years ago

it seems to work ok.