Skip to content

Commit

Permalink
Fix null reference exception
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Oct 17, 2023
1 parent 3bfa943 commit b1926c0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Source/MQTTnet/Client/MqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,9 @@ async Task ProcessReceivedPublishPackets(CancellationToken cancellationToken)
await eventArgs.AcknowledgeAsync(cancellationToken).ConfigureAwait(false);
}
}
catch (ObjectDisposedException)
{
}
catch (OperationCanceledException)
{
}
Expand Down Expand Up @@ -787,7 +790,7 @@ async Task ReceivePacketsLoop(CancellationToken cancellationToken)
{
try
{
_logger.Verbose("Start receiving packets.");
_logger.Verbose("Start receiving packets");

while (!cancellationToken.IsCancellationRequested)
{
Expand Down Expand Up @@ -825,20 +828,22 @@ async Task ReceivePacketsLoop(CancellationToken cancellationToken)
}
else if (exception is MqttCommunicationException)
{
_logger.Warning(exception, "Communication error while receiving packets.");
_logger.Warning(exception, "Communication error while receiving packets");
}
else
{
_logger.Error(exception, "Error while receiving packets.");
_logger.Error(exception, "Error while receiving packets");
}

_packetDispatcher.FailAll(exception);
// The packet dispatcher is set to null when the client is being disposed so it may
// already being gone!
_packetDispatcher?.FailAll(exception);

await DisconnectInternal(_packetReceiverTask, exception, null).ConfigureAwait(false);
}
finally
{
_logger.Verbose("Stopped receiving packets.");
_logger.Verbose("Stopped receiving packets");
}
}

Expand Down

0 comments on commit b1926c0

Please sign in to comment.