diff --git a/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/ActiveClientLinkManager.cs b/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/ActiveClientLinkManager.cs index 023e21b9142c7..9278dd9d3ce73 100644 --- a/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/ActiveClientLinkManager.cs +++ b/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/ActiveClientLinkManager.cs @@ -125,12 +125,16 @@ void OnRequestResponseLinkClosed(object sender, EventArgs e) void SetRenewCbsTokenTimer(ActiveClientLinkObject activeClientLinkObject) { - if (activeClientLinkObject.AuthorizationValidUntilUtc < DateTime.UtcNow) + var utcNow = DateTime.UtcNow; + if (activeClientLinkObject.AuthorizationValidUntilUtc < utcNow) { return; } - var interval = activeClientLinkObject.AuthorizationValidUntilUtc.Subtract(DateTime.UtcNow) - ActiveClientLinkManager.TokenRefreshBuffer; + var interval = activeClientLinkObject.AuthorizationValidUntilUtc.Subtract(utcNow) - ActiveClientLinkManager.TokenRefreshBuffer; + if (interval < ActiveClientLinkManager.TokenRefreshBuffer) + interval = TimeSpan.Zero; + interval = TimeoutHelper.Min(interval, ActiveClientLinkManager.MaxTokenRefreshTime); this.ChangeRenewTimer(activeClientLinkObject, interval);