Fixed an issue with queued client message in the server.

This commit is contained in:
Christian Kratky
2017-11-07 23:30:15 +01:00
parent 6e5b991406
commit f481c704c9
4 changed files with 56 additions and 6 deletions
@@ -59,11 +59,12 @@ namespace MQTTnet.Core.Server
private async Task SendPendingPublishPacketAsync(IMqttCommunicationAdapter adapter, CancellationToken cancellationToken)
{
var packet = _pendingPublishPackets.Take(cancellationToken);
MqttPublishPacket packet = null;
try
{
packet = _pendingPublishPackets.Take(cancellationToken);
await adapter.SendPacketsAsync(_options.DefaultCommunicationTimeout, cancellationToken, packet).ConfigureAwait(false);
_logger.LogTrace("Enqueued packet sent (ClientId: {0}).", _session.ClientId);
}
catch (Exception exception)
@@ -84,10 +85,10 @@ namespace MQTTnet.Core.Server
_logger.LogError(new EventId(), exception, "Sending publish packet failed (ClientId: {0}).", _session.ClientId);
}
if (packet.QualityOfServiceLevel > MqttQualityOfServiceLevel.AtMostOnce)
if (packet != null && packet.QualityOfServiceLevel > MqttQualityOfServiceLevel.AtMostOnce)
{
packet.Dup = true;
_pendingPublishPackets.Add(packet, cancellationToken);
_pendingPublishPackets.Add(packet, CancellationToken.None);
}
_session.Stop();