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

Utilize retry policy when retrying to send SAS token in CBS auth in AMQP #3074

Merged
merged 13 commits into from
Jan 24, 2023

Conversation

schoims
Copy link
Contributor

@schoims schoims commented Jan 17, 2023

Refactored how retryPolicy is set in RetryDelegatingHandler. It is passed as a PipelineContext property. This change eliminates the need for setting it with a default RetryPolicy and updating it later.
AMQP implements proactive SAS token renewal support. This logic has been moved from AmqpAuthenticationRefresher to RetryDelegatingHandler to utilize retryHandler. When deviceClient calls OpenAsync(), AmqpIoTConnection creates amqpAuthenticationRefresher and amqpAuthenticationRefresher.refreshTokenAsync() sends a token to AmqpIotCbsTokenProvider for the first time and then gets a dateTime variable. This variable represents the token expiry time in UTC.

@Azure Azure deleted a comment from azure-pipelines bot Jan 17, 2023
@Azure Azure deleted a comment from azure-pipelines bot Jan 17, 2023
@schoims
Copy link
Contributor Author

schoims commented Jan 17, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@schoims
Copy link
Contributor Author

schoims commented Jan 17, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@schoims schoims force-pushed the choisophia/refresh-token-2 branch from 6cd36f1 to 9144246 Compare January 19, 2023 20:57
@schoims
Copy link
Contributor Author

schoims commented Jan 19, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -62,9 +62,10 @@ public abstract class IotHubBaseClient : IAsyncDisposable
DesiredPropertyUpdateCallback = OnDesiredStatePatchReceived,
ConnectionStatusChangeHandler = OnConnectionStatusChanged,
MessageEventCallback = OnMessageReceivedAsync,
RetryPolicy = _clientOptions.RetryPolicy ?? new IotHubClientNoRetry(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Set RetryPolicy with the default exponential backoff policy unless user set it to null which is IotHubClientNoRetry()

if (_clientOptions.TransportSettings is IotHubClientAmqpSettings)
{
InnerHandler.SetSasTokenRefreshesOn();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sets SAS token refreshes on only for AMQP


if (_clientOptions.TransportSettings is IotHubClientAmqpSettings)
{
await InnerHandler.StopSasTokenLoopAsync().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.

Stop SAS token refresh loop only for AMQP

@schoims
Copy link
Contributor Author

schoims commented Jan 19, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

[DataRow(IotHubClientErrorCode.ServerError)]
[DataRow(IotHubClientErrorCode.ServerBusy)]
[DataRow(IotHubClientErrorCode.Timeout)]
public async Task RetryDelegatingHandler_RefreshSasTokenAsync_RetriesOnTransientErrors(IotHubClientErrorCode errorCode)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Retries on all transient errors including network errors

[DataRow(IotHubClientErrorCode.Unauthorized)]
[DataRow(IotHubClientErrorCode.TlsAuthenticationError)]
[DataRow(IotHubClientErrorCode.ArgumentInvalid)]
public async Task RetryDelegatingHandler_RefreshSasTokenAsync_NoRetriesOnNonTransientErrors(IotHubClientErrorCode errorCode)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does not retry on non-transient errors

@schoims
Copy link
Contributor Author

schoims commented Jan 23, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines 536 to 540
try
{
if (Logging.IsEnabled)
Logging.Enter(this, nameof(StopSasTokenLoopAsync));

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
try
{
if (Logging.IsEnabled)
Logging.Enter(this, nameof(StopSasTokenLoopAsync));
if (Logging.IsEnabled)
Logging.Enter(this, nameof(StopSasTokenLoopAsync));
try
{

@schoims schoims changed the title Choisophia/refresh token 2 Utilize retry policy when retrying to send SAS token in CBS auth in AMQP Jan 24, 2023
@schoims
Copy link
Contributor Author

schoims commented Jan 24, 2023

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@schoims schoims merged commit 42d5e5f into previews/v2 Jan 24, 2023
@schoims schoims deleted the choisophia/refresh-token-2 branch January 24, 2023 01:30
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.

2 participants