From 35ba8cd0b0dabaf2d1e70f3c9f4d2ca19aa77c4e Mon Sep 17 00:00:00 2001 From: Neeraj Makam Date: Tue, 30 Jul 2019 13:47:46 -0700 Subject: [PATCH] Ensure if link has been authorized for a time less than TokenRefreshBuffer, it doesn't lead to unexpected errors. --- .../src/Amqp/ActiveClientLinkManager.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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);