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

Prevent pump from stop processing by ignoring ObjectDisposedException #6510

Closed
wants to merge 1 commit into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,20 @@ public void StartPump()

static void CancelAndDisposeCancellationTokenSource(CancellationTokenSource renewLockCancellationTokenSource)
{
renewLockCancellationTokenSource?.Cancel();
renewLockCancellationTokenSource?.Dispose();
try
{
renewLockCancellationTokenSource?.Cancel();
renewLockCancellationTokenSource?.Dispose();
}
catch (ObjectDisposedException)
{
// just ignore - token source might be already disposed by timer callback
}
}

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

bool ShouldRenewSessionLock()
Expand Down Expand Up @@ -151,7 +156,7 @@ async Task SessionPumpTaskAsync()
{
if (!(exception is ObjectDisposedException && this.pumpCancellationToken.IsCancellationRequested))
{
await this.RaiseExceptionReceived(exception, ExceptionReceivedEventArgsAction.AcceptMessageSession).ConfigureAwait(false);
await this.RaiseExceptionReceived(exception, ExceptionReceivedEventArgsAction.AcceptMessageSession).ConfigureAwait(false);
}
if (!MessagingUtilities.ShouldRetry(exception))
{
Expand Down Expand Up @@ -205,7 +210,7 @@ async Task MessagePumpTaskAsync(IMessageSession session)

if (!(exception is ObjectDisposedException && this.pumpCancellationToken.IsCancellationRequested))
{
await this.RaiseExceptionReceived(exception, ExceptionReceivedEventArgsAction.Receive).ConfigureAwait(false);
await this.RaiseExceptionReceived(exception, ExceptionReceivedEventArgsAction.Receive).ConfigureAwait(false);
}
break;
}
Expand Down Expand Up @@ -321,7 +326,7 @@ async Task RenewSessionLockTaskAsync(IMessageSession session, CancellationToken
MessagingEventSource.Log.SessionReceivePumpSessionRenewLockException(this.clientId, session.SessionId, exception);

// TaskCanceled is expected here as renewTasks will be cancelled after the Complete call is made.
// ObjectDisposedException should only happen here because the CancellationToken was disposed at which point
// ObjectDisposedException should only happen here because the CancellationToken was disposed at which point
// this renew exception is not relevant anymore. Lets not bother user with this exception.
if (!(exception is TaskCanceledException) && !(exception is ObjectDisposedException))
{
Expand Down