MQTTnet: Stream ReadAsync stuck bug
Hi, I got the bug when after timeout the client connection was not closed, it hangs for long time inside ReadAsync. Even when cancellation token was raised. I see your notice in the MqttTcpChannel.Dispose() method about stream disposing, but it should be like:
_stream?.Dispose();
_stream = null;
_socket?.Dispose();
_socket = null;
Disposing only _stream does not cancel ReadAsync in my case, so _socket should be also disposed.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (1 by maintainers)
I maybe found a reason. I added a UnitTest but it worked as expected. The socket was disposed perfectly. The stream will dispose the socket internally on its own dispose. The hierarchy is
NetworkStream > Socket. But when I checked the chain for SSL connections it was broken. The hierarchy isSslStream > Networkstream > Socket. So the disposal of the SSL stream should close the networks stream and the network stream should dispose the socket. But this was broken because of wrong parameters for stream constructors. That`s why you needed to dispose the socket. Are you using SSL connections? Or is this maybe another issue?The fix is already pushed to develop branch.