-
Notifications
You must be signed in to change notification settings - Fork 492
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
Conversation
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
6cd36f1
to
9144246
Compare
/azp run |
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(), |
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.
Set RetryPolicy with the default exponential backoff policy unless user set it to null which is IotHubClientNoRetry()
if (_clientOptions.TransportSettings is IotHubClientAmqpSettings) | ||
{ | ||
InnerHandler.SetSasTokenRefreshesOn(); | ||
} |
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.
Sets SAS token refreshes on only for AMQP
|
||
if (_clientOptions.TransportSettings is IotHubClientAmqpSettings) | ||
{ | ||
await InnerHandler.StopSasTokenLoopAsync().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.
Stop SAS token refresh loop only for AMQP
/azp run |
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) |
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.
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) |
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.
Does not retry on non-transient errors
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
try | ||
{ | ||
if (Logging.IsEnabled) | ||
Logging.Enter(this, nameof(StopSasTokenLoopAsync)); | ||
|
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.
try | |
{ | |
if (Logging.IsEnabled) | |
Logging.Enter(this, nameof(StopSasTokenLoopAsync)); | |
if (Logging.IsEnabled) | |
Logging.Enter(this, nameof(StopSasTokenLoopAsync)); | |
try | |
{ |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
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.