Fix infinite loop that can occur when the client closes the connection before sending the complete packet body.

This commit is contained in:
kpreisser
2018-01-23 10:45:58 +01:00
parent 8b2b8d41df
commit d020e809a1
@@ -137,6 +137,12 @@ namespace MQTTnet.Adapter
do
{
var readBytesCount = await stream.ReadAsync(body, offset, body.Length - offset, cancellationToken).ConfigureAwait(false);
// Check if the client closed the connection before sending the full body.
if (readBytesCount == 0)
{
throw new MqttCommunicationException("Connection closed while reading remaining packet body.");
}
offset += readBytesCount;
} while (offset < header.BodyLength);