diff --git a/e2e/LongHaul/device/IotHub.cs b/e2e/LongHaul/device/IotHub.cs index 25f42db34f..3a8ebfe4ea 100644 --- a/e2e/LongHaul/device/IotHub.cs +++ b/e2e/LongHaul/device/IotHub.cs @@ -124,7 +124,7 @@ public async Task SendTelemetryMessagesAsync(Logger logger, CancellationToken ct { await Task.Delay(s_messageLoopSleepTime, ct).ConfigureAwait(false); } - catch (TaskCanceledException) + catch (OperationCanceledException) { // App is signalled to exit _logger.Trace($"Exit signal encountered. Terminating telemetry message pump.", TraceSeverity.Verbose); @@ -169,12 +169,13 @@ public async Task SendTelemetryMessagesAsync(Logger logger, CancellationToken ct { if (pendingMessages.Count > 1) { - logger.Trace($"Sending {pendingMessages.Count} messages in bulk."); + logger.Trace($"Sending {pendingMessages.Count} telemetry messages in bulk.", TraceSeverity.Information); sw.Restart(); await _deviceClient.SendTelemetryAsync(pendingMessages, ct).ConfigureAwait(false); } else { + logger.Trace("Sending a telemetry message.", TraceSeverity.Information); sw.Restart(); await _deviceClient.SendTelemetryAsync(pendingMessages.First(), ct).ConfigureAwait(false); } @@ -206,6 +207,7 @@ public async Task ReportReadOnlyPropertiesAsync(Logger logger, CancellationToken { "TotalTelemetryMessagesSent", _totalTelemetryMessagesSent }, }; + logger.Trace($"Updating reported properties.", TraceSeverity.Information); sw.Restart(); await _deviceClient.UpdateReportedPropertiesAsync(reported, ct).ConfigureAwait(false); sw.Stop(); diff --git a/e2e/LongHaul/device/Parameters.cs b/e2e/LongHaul/device/Parameters.cs index df41807c37..a4856e9b8f 100644 --- a/e2e/LongHaul/device/Parameters.cs +++ b/e2e/LongHaul/device/Parameters.cs @@ -48,7 +48,7 @@ internal class Parameters "TransportProtocol", Default = IotHubClientTransportProtocol.Tcp, Required = false, - HelpText = "The protocol over which a transport (i.e., MQTT, AMQP) communicates.")] + HelpText = "The protocol over which a transport communicates (i.e., Tcp, WebSocket).")] public IotHubClientTransportProtocol TransportProtocol { get; set; } [Option( diff --git a/e2e/LongHaul/device/Program.cs b/e2e/LongHaul/device/Program.cs index 3b91eed5c0..8e49fafee8 100644 --- a/e2e/LongHaul/device/Program.cs +++ b/e2e/LongHaul/device/Program.cs @@ -94,7 +94,7 @@ await Task iotHub.UploadFilesAsync(s_logger.Clone(), cancellationTokenSource.Token)) .ConfigureAwait(false); } - catch (TaskCanceledException) { } // user signalled an exit + catch (OperationCanceledException) { } // user signalled an exit catch (Exception ex) { s_logger.Trace($"Device app failed with exception {ex}", TraceSeverity.Error); diff --git a/iothub/device/src/Transport/AmqpIot/AmqpIotSendingLink.cs b/iothub/device/src/Transport/AmqpIot/AmqpIotSendingLink.cs index 784af72feb..bd1c152fde 100644 --- a/iothub/device/src/Transport/AmqpIot/AmqpIotSendingLink.cs +++ b/iothub/device/src/Transport/AmqpIot/AmqpIotSendingLink.cs @@ -133,6 +133,15 @@ private async Task SendAmqpMessageAsync(AmqpMessage amqpMessage, Cancel catch (Exception ex) when (!Fx.IsFatal(ex)) { Exception iotEx = AmqpIotExceptionAdapter.ConvertToIotHubException(ex, _sendingAmqpLink); + + if (iotEx is OperationCanceledException && !cancellationToken.IsCancellationRequested) + { + // OperationCanceledException may be thrown here when there is networking disconnect + // even if cancellation has not been requested yet. This case is treated as a transient + // network error rather than an OperationCanceledException. + throw new IotHubClientException(iotEx.Message, IotHubClientErrorCode.NetworkErrors, iotEx); + } + if (ReferenceEquals(ex, iotEx)) { throw;