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

Add M2M message failure fixes to lts_2021_03 #3006

Merged
merged 1 commit into from
Dec 12, 2022

Conversation

schoims
Copy link
Contributor

@schoims schoims commented Dec 6, 2022

Bringing in

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);
Copy link
Contributor Author

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

@schoims schoims marked this pull request as ready for review December 7, 2022 19:01
@schoims
Copy link
Contributor Author

schoims commented Dec 7, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@schoims
Copy link
Contributor Author

schoims commented Dec 8, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@schoims
Copy link
Contributor Author

schoims commented Dec 8, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@tmahmood-microsoft
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

{
Logging.Info(this, $"{nameof(StopLoop)}");
_refresherCancellationTokenSource?.Cancel();
}
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, updated accordingly.

@schoims schoims changed the title Add fixes to lts Add AMQP token refresher cancellation and M2M message failure fixes to lts Dec 9, 2022
@schoims
Copy link
Contributor Author

schoims commented Dec 9, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@schoims
Copy link
Contributor Author

schoims commented Dec 9, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@schoims schoims changed the title Add AMQP token refresher cancellation and M2M message failure fixes to lts Add AMQP token refresher cancellation and M2M message failure fixes to lts_2021_03 Dec 9, 2022
// 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.
Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

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.

Comment on lines 203 to 207
catch (Exception ex)
{
if (Logging.IsEnabled)
Logging.Error(this, $"Exception caught while canceling SAS token refresh loop: {ex}", nameof(StopLoop));
}
Copy link
Contributor

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));

@schoims schoims changed the title Add AMQP token refresher cancellation and M2M message failure fixes to lts_2021_03 Add M2M message failure fixes to lts_2021_03 Dec 12, 2022
@schoims
Copy link
Contributor Author

schoims commented Dec 12, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants