in dotnet/src/Azure.Iot.Operations.Mqtt/Session/MqttSessionClient.cs [800:859]
private static bool IsFatal(Exception e, bool userCancellationRequested = false)
{
if (e is MqttConnectingFailedException)
{
MqttClientConnectResultCode code = ((MqttConnectingFailedException)e).ResultCode;
switch (code)
{
case MqttClientConnectResultCode.MalformedPacket:
case MqttClientConnectResultCode.ProtocolError:
case MqttClientConnectResultCode.UnsupportedProtocolVersion:
case MqttClientConnectResultCode.ClientIdentifierNotValid:
case MqttClientConnectResultCode.BadUserNameOrPassword:
case MqttClientConnectResultCode.Banned:
case MqttClientConnectResultCode.BadAuthenticationMethod:
case MqttClientConnectResultCode.TopicNameInvalid:
case MqttClientConnectResultCode.PacketTooLarge:
case MqttClientConnectResultCode.PayloadFormatInvalid:
case MqttClientConnectResultCode.RetainNotSupported:
case MqttClientConnectResultCode.QoSNotSupported:
case MqttClientConnectResultCode.ServerMoved:
case MqttClientConnectResultCode.ImplementationSpecificError:
case MqttClientConnectResultCode.UseAnotherServer:
case MqttClientConnectResultCode.NotAuthorized:
return true;
}
}
if (e is SocketException)
{
//TODO there is room for a lot more nuance here. Some socket exceptions are more retryable than others so it may
// be inappropriate to label them all as fatal.
return true;
}
if (e is MQTTnet.Exceptions.MqttProtocolViolationException)
{
return true;
}
if (e is ArgumentException
|| e is ArgumentNullException
|| e is NotSupportedException)
{
return true;
}
// MQTTnet may throw an OperationCanceledException/TaskCanceledException even if
// neither the user nor the session client provides a cancellation token. Because
// of that, this exception is only fatal if the cancellation token this layer
// is aware of actually requested cancellation. Other cases signify that MQTTnet
// gave up on the operation, but the user still wants to retry.
if ((e is OperationCanceledException || e is TaskCanceledException)
&& userCancellationRequested)
{
return true;
}
return false;
}