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

Cancel twin ops on disconnect #3287

Merged
merged 29 commits into from
Apr 20, 2023
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
5ebb0fe
Cancel pending twin operations on disconnect
Apr 19, 2023
d831d48
Add/update logging
Apr 19, 2023
9ea0ec6
Reduce concurrent dictionaries to one per protocol
Apr 19, 2023
8fce7e6
Fix twin patch response
Apr 19, 2023
19a8e0a
Unify twin update and logging in long haul
Apr 19, 2023
9dd4909
Improve error handling in long haul
Apr 19, 2023
2eee027
Fix old task cleanup
Apr 20, 2023
9b86af4
Add retry to long haul init
Apr 20, 2023
a6d0f39
merge
Apr 20, 2023
0a6014b
Rearrange methods
Apr 20, 2023
287a8fa
Fix method name
Apr 20, 2023
1593b03
PR feedback from Bryce
Apr 20, 2023
eb8b7b3
Cancel pending twin operations on disconnect
Apr 19, 2023
99b9b7d
Add/update logging
Apr 19, 2023
586e53d
Reduce concurrent dictionaries to one per protocol
Apr 19, 2023
b8d858f
Fix twin patch response
Apr 19, 2023
4f68177
Unify twin update and logging in long haul
Apr 19, 2023
348e82b
Improve error handling in long haul
Apr 19, 2023
ed93221
Fix old task cleanup
Apr 20, 2023
3b2654e
Add retry to long haul init
Apr 20, 2023
c74dc83
merge
Apr 20, 2023
365968c
Rearrange methods
Apr 20, 2023
0eabbb1
Fix method name
Apr 20, 2023
fcd79d3
PR feedback from Bryce
Apr 20, 2023
af27f20
PR feedback
Apr 20, 2023
0fb999d
adding cancellation toke for InitializeAsync in module client
tmahmood-microsoft Apr 20, 2023
d418081
Merge branch 'drwill/cancel-twinops-on-disconnect' of https://github.…
tmahmood-microsoft Apr 20, 2023
f45d3fc
Fix MQTT twin response
Apr 20, 2023
04fa965
Add unit tests for payload conventions
Apr 20, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix old task cleanup
David R. Williamson committed Apr 20, 2023
commit 2eee027f2b5ac7ca6e3cc5aedd9687148afa4417
12 changes: 8 additions & 4 deletions iothub/device/src/Pipeline/AmqpTransportHandler.cs
Original file line number Diff line number Diff line change
@@ -533,19 +533,23 @@ private void RemoveOldOperations(object state)
if (Logging.IsEnabled)
Logging.Info(this, $"Removing operations older than {maxAge}", nameof(RemoveOldOperations));

_ = _pendingTwinOperations
.Where(x => DateTimeOffset.UtcNow - x.Value.RequestSentOnUtc > s_twinResponseTimeout)
int canceledOperations = _pendingTwinOperations
.Where(x => DateTimeOffset.UtcNow - x.Value.RequestSentOnUtc > maxAge)
.Select(x =>
{
if (_pendingTwinOperations.TryRemove(x.Key, out PendingAmqpTwinOperation pendingOperation))
{
if (Logging.IsEnabled)
Logging.Info(this, $"Removing twin response for {x.Key}", nameof(RemoveOldOperations));
Logging.Error(this, $"Removing twin response for {x.Key}", nameof(RemoveOldOperations));

pendingOperation.CompletionTask.TrySetException(new IotHubClientException("Did not receive twin response from service.", IotHubClientErrorCode.NetworkErrors));
}
return true;
});
})
.Count();
drwill-ms marked this conversation as resolved.
Show resolved Hide resolved

if (Logging.IsEnabled)
Logging.Error(this, $"Remnoved {canceledOperations} twin responses", nameof(RemoveOldOperations));
drwill-ms marked this conversation as resolved.
Show resolved Hide resolved
}

protected private override void Dispose(bool disposing)
8 changes: 6 additions & 2 deletions iothub/device/src/Pipeline/MqttTransportHandler.cs
Original file line number Diff line number Diff line change
@@ -1362,7 +1362,7 @@ private void RemoveOldOperations(object state)
Logging.Info(this, $"Removing operations older than {maxAge}", nameof(RemoveOldOperations));

const string exceptionMessage = "Did not receive twin response from service.";
_ = _pendingTwinOperations
int canceledOperations = _pendingTwinOperations
.Where(x => DateTimeOffset.UtcNow - x.Value.RequestSentOnUtc > maxAge)
.Select(x =>
{
@@ -1375,7 +1375,11 @@ private void RemoveOldOperations(object state)
pendingOperation.TwinPatchTask?.TrySetException(new IotHubClientException(exceptionMessage, IotHubClientErrorCode.NetworkErrors));
}
return true;
});
})
.Count();

if (Logging.IsEnabled)
Logging.Error(this, $"Remnoved {canceledOperations} twin responses", nameof(RemoveOldOperations));
drwill-ms marked this conversation as resolved.
Show resolved Hide resolved
}

private static void PopulateMessagePropertiesFromMqttMessage(IncomingMessage message, MqttApplicationMessage mqttMessage)