dotnet / dotnet/MQTTnet

MQTTNet hung during call to ManagedMQTTClient.Dispose()

Open
#765 12 comments 0 reactions 0 assignees View on GitHub
bug managed-client
Dominant language
C#
Stars
5.1k
Forks
1.2k
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug
During a network outage, we experienced a hang in the Dispose call of the ManagedMQTTClient at [this location in the code](https://github.com/chkr1011/MQTTnet/blob/2918be18c6c6529584cd1d78e09ebb3fc0819e4f/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs#L251). It's unclear precisely what happened to cause this situation other than the environmental situation which I just described: a network outage.

### Which project is your bug related to?
- ManagedClient

### To Reproduce
Steps to reproduce the behavior:
1. Using this version of MQTTnet v4.0.30319.
2. Run [this](https://github.com/chkr1011/MQTTnet/blob/2918be18c6c6529584cd1d78e09ebb3fc0819e4f/Source/MQTTnet.Extensions.ManagedClient/ManagedMqttClient.cs#L251) code.
3. With these arguments: None.
4. See a hang if the _maintainConnectionTask never completes.

### Expected behavior
I expect the code to eventually timeout and/or toss a timeout exception as opposed to hanging indefinitely. Our software will restart the box if we notice something (like a bad network) has happened, but we also expected the underlying software to not hang during shutdown. This resulted in our product not successfully restarting the box and manual resets being required.

We could trap a timeout exception and handle it the best we can during shutdown, but we cannot hang indefinitely.

### Screenshots
I managed to create a dump of the process that hung, and one of the threads showed this:
![image](https://user-images.githubusercontent.com/526471/66070356-c5146480-e516-11e9-915b-38f0d0c17621.png)
.

### Additional context / logging
NA

### Code example
NA

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.