-
Notifications
You must be signed in to change notification settings - Fork 491
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
Add M2M message failure fixes to lts_2021_03 #3006
Conversation
if (((PublishPacket)packet).QualityOfService == QualityOfService.AtLeastOnce && | ||
((PublishPacket)packet).TopicName.StartsWith(MqttTransportHandler.MethodPostTopicPrefix, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
await AcknowledgeAsync(context, ((PublishPacket)packet).PacketId.ToString(CultureInfo.InvariantCulture)).ConfigureAwait(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToString method required IFormatProvider to be specified, so added CultureInfo.InvariantCulture
iothub/device/src/Transport/Amqp/AmqpAuthenticationRefresher.cs
Outdated
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
a1cb21d
to
2bec37a
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
{ | ||
Logging.Info(this, $"{nameof(StopLoop)}"); | ||
_refresherCancellationTokenSource?.Cancel(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should it wait for the loop to end? We have cached the Task from it, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot wait for the loop to end since this is an infinite loop. Control will exit the loop only when the cancellation token is signaled for cancellation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This an unmonitored loop running on a separate thread.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but you just canceled it on line 181, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought awaiting on the loop in here might help us catch an OperationCancelledException in the RefreshLoopAsync running unmonitored, but it turns out the only place we refer to the cancellation token is when we check it manually for cancellation. So, the API method should not encounter OperationCancellationException.
Would there be any advantage to us awaiting this loop then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awaiting for any exception and logging it.
If we don't await it, let's make sure that method does not throw, and logs anything it catches.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, updated accordingly.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
627dde3
to
def7607
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
// StopLoop ensures that the resources related to token refresher are cancelled and ready for cleanup. | ||
// It will cancel the associated cancellation token source and will await completion of the refresh loop task. | ||
// Any exceptions thrown as a result of these operations are caught and logged. | ||
// StopLoop will not generate any exceptions so it safe for us to declare this as async void. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still don't do this. It hurts nothing to return a Task.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. I would have liked to return a Task but the way this call chains up prevents us from returning a Task.
This is invoked from within Dispose() and certain event handlers that return void, so we can either makie this fire-forget or block on this task within the caller.
Since this method isn't expected to have any undesireable side-effect, making this fire-forget seemed like the better option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call chain doesn't prevent this from returning a task. It just prevents the callers from awaiting it.
Also, we can choose to use IAsyncDisposable, if we wish.
catch (Exception ex) | ||
{ | ||
if (Logging.IsEnabled) | ||
Logging.Error(this, $"Exception caught while canceling SAS token refresh loop: {ex}", nameof(StopLoop)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This try/catch should cover the entire method, including logging and the CTS cancel.
catch (Exception ex) | ||
{ | ||
if (Logging.IsEnabled) | ||
Logging.Error(this, $"Exception caught while canceling SAS token refresh loop: {ex}", nameof(StopLoop)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logging.Error(this, $"Exception caught while canceling SAS token refresh loop: {ex}", nameof(StopLoop)); | |
Logging.Error(this, $"Exception caught while waiting for SAS token refresh loop to exit: {ex}", nameof(StopLoop)); |
5ebfc54
to
9e4844c
Compare
9e4844c
to
2d5e1de
Compare
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Bringing in