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

Fixes session pump stop when auto-renew lock task expires #6483

Merged
merged 1 commit into from
Jul 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 18 additions & 15 deletions sdk/servicebus/Microsoft.Azure.ServiceBus/src/SessionReceivePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,18 @@ public void StartPump()
}
}

static void CancelAndDisposeCancellationTokenSource(CancellationTokenSource renewLockCancellationTokenSource)
{
renewLockCancellationTokenSource?.Cancel();
renewLockCancellationTokenSource?.Dispose();
}

static void OnUserCallBackTimeout(object state)
static void CancelAutoRenewLock(object state)
{
var renewCancellationTokenSource = (CancellationTokenSource)state;
renewCancellationTokenSource?.Cancel();
renewCancellationTokenSource?.Dispose();

try
{
renewCancellationTokenSource.Cancel();
}
catch (ObjectDisposedException)
{
// Ignore this race.
}
}

bool ShouldRenewSessionLock()
Expand Down Expand Up @@ -179,8 +180,8 @@ async Task MessagePumpTaskAsync(IMessageSession session)
TaskExtensionHelper.Schedule(() => this.RenewSessionLockTaskAsync(session, renewLockCancellationTokenSource.Token));
}

var userCallbackTimer = new Timer(
OnUserCallBackTimeout,
var autoRenewLockCancellationTimer = new Timer(
CancelAutoRenewLock,
renewLockCancellationTokenSource,
Timeout.Infinite,
Timeout.Infinite);
Expand Down Expand Up @@ -223,7 +224,7 @@ async Task MessagePumpTaskAsync(IMessageSession session)
try
{
// Set the timer
userCallbackTimer.Change(this.sessionHandlerOptions.MaxAutoRenewDuration,
autoRenewLockCancellationTimer.Change(this.sessionHandlerOptions.MaxAutoRenewDuration,
TimeSpan.FromMilliseconds(-1));
var callbackExceptionOccurred = false;
try
Expand All @@ -248,7 +249,7 @@ async Task MessagePumpTaskAsync(IMessageSession session)
}
finally
{
userCallbackTimer.Change(Timeout.Infinite, Timeout.Infinite);
autoRenewLockCancellationTimer.Change(Timeout.Infinite, Timeout.Infinite);
}

if (!callbackExceptionOccurred)
Expand All @@ -269,8 +270,10 @@ async Task MessagePumpTaskAsync(IMessageSession session)
}
finally
{
userCallbackTimer.Dispose();
CancelAndDisposeCancellationTokenSource(renewLockCancellationTokenSource);
renewLockCancellationTokenSource.Cancel();
renewLockCancellationTokenSource.Dispose();
autoRenewLockCancellationTimer.Dispose();

await this.CloseSessionIfNeededAsync(session).ConfigureAwait(false);
this.maxConcurrentSessionsSemaphoreSlim.Release();
}
Expand Down