Merge pull request #163 from kpreisser/fixInfiniteLoop

Fix infinite loop when the client closes the connection
This commit is contained in:
Christian
2018-01-24 20:12:15 +01:00
committed by GitHub
@@ -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);