Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where device operations not recovering after reconnect #3281

Merged
merged 2 commits into from Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions e2e/LongHaul/device/IotHub.cs
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion e2e/LongHaul/device/Parameters.cs
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion e2e/LongHaul/device/Program.cs
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions iothub/device/src/Transport/AmqpIot/AmqpIotSendingLink.cs
Expand Up @@ -133,6 +133,15 @@ private async Task<Outcome> 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;
Expand Down