Skip to content

Commit

Permalink
Imrpove client disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
chkr1011 committed Nov 4, 2023
1 parent 1ba8f74 commit 1bebf7d
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions Source/MQTTnet/Client/MqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ async Task ProcessReceivedPublishPackets(CancellationToken cancellationToken)
}
catch (Exception exception)
{
_logger.Error(exception, "Error while handling application message.");
_logger.Error(exception, "Error while handling application message");
}
}
}
Expand Down Expand Up @@ -835,8 +835,7 @@ async Task ReceivePacketsLoop(CancellationToken cancellationToken)
_logger.Error(exception, "Error while receiving packets");
}

// The packet dispatcher is set to null when the client is being disposed so it may
// already being gone!
// 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);
Expand Down Expand Up @@ -865,7 +864,7 @@ async Task<TResponsePacket> Request<TResponsePacket>(MqttPacket requestPacket, C
}
catch (Exception exception)
{
_logger.Warning(exception, "Error when sending request packet ({0}).", requestPacket.GetType().Name);
_logger.Warning(exception, "Error when sending {0} request packet", requestPacket.GetType().Name);
packetAwaitable.Fail(exception);
}

Expand All @@ -877,7 +876,7 @@ async Task<TResponsePacket> Request<TResponsePacket>(MqttPacket requestPacket, C
{
if (exception is MqttCommunicationTimedOutException)
{
_logger.Warning("Timeout while waiting for response packet ({0}).", typeof(TResponsePacket).Name);
_logger.Warning("Timeout while waiting for {0} response packet", typeof(TResponsePacket).Name);
}

throw;
Expand Down Expand Up @@ -943,7 +942,7 @@ void TryInitiateDisconnect()
}
catch (Exception exception)
{
_logger.Warning(exception, "Error while initiating disconnect.");
_logger.Warning(exception, "Error while initiating disconnect");
}
}
}
Expand Down Expand Up @@ -978,7 +977,7 @@ async Task TryProcessReceivedPacket(MqttPacket packet, CancellationToken cancell
}
else if (packet is MqttPingReqPacket)
{
throw new MqttProtocolViolationException("The PINGREQ Packet is sent from a Client to the Server only.");
throw new MqttProtocolViolationException("The PINGREQ Packet is sent from a client to the server only.");
}
else
{
Expand All @@ -1000,14 +999,15 @@ async Task TryProcessReceivedPacket(MqttPacket packet, CancellationToken cancell
}
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 processing received packet ({packet.GetType().Name}).");
_logger.Error(exception, "Error while processing received {0} packet", packet.GetType().Name);
}

_packetDispatcher.FailAll(exception);
// The packet dispatcher may already be gone due to disconnect etc!
_packetDispatcher?.FailAll(exception);

await DisconnectInternal(_packetReceiverTask, exception, null).ConfigureAwait(false);
}
Expand All @@ -1017,7 +1017,7 @@ async Task TrySendKeepAliveMessages(CancellationToken cancellationToken)
{
try
{
_logger.Verbose("Start sending keep alive packets.");
_logger.Verbose("Start sending keep alive packets");

var keepAlivePeriod = Options.KeepAlivePeriod;

Expand Down Expand Up @@ -1055,18 +1055,18 @@ async Task TrySendKeepAliveMessages(CancellationToken cancellationToken)
}
else if (exception is MqttCommunicationException)
{
_logger.Warning(exception, "Communication error while sending/receiving keep alive packets.");
_logger.Warning(exception, "Communication error while sending/receiving keep alive packets");
}
else
{
_logger.Error(exception, "Error exception while sending/receiving keep alive packets.");
_logger.Error(exception, "Error exception while sending/receiving keep alive packets");
}

await DisconnectInternal(_keepAlivePacketsSenderTask, exception, null).ConfigureAwait(false);
}
finally
{
_logger.Verbose("Stopped sending keep alive packets.");
_logger.Verbose("Stopped sending keep alive packets");
}
}
}
Expand Down

0 comments on commit 1bebf7d

Please sign in to comment.