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

Ensure SessionReceiverManager is cleaned up when closing #23121

Merged
merged 7 commits into from
Aug 6, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -941,6 +941,7 @@ await receiverManager.CloseReceiverIfNeeded(
public async ValueTask DisposeAsync()
{
await CloseAsync().ConfigureAwait(false);
_handlerCts.Dispose();
GC.SuppressFinalize(this);
}

Expand Down Expand Up @@ -980,6 +981,7 @@ private void WakeLoop()
// wake up the handler loop
var handlerCts = Interlocked.Exchange(ref _handlerCts, new CancellationTokenSource());
handlerCts.Cancel();
handlerCts.Dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm 78% certain you don't need to dispose after cancel.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It made Rider happy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

}

private async Task ReconcileConcurrencyAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -635,9 +635,8 @@ public async Task AutoLockRenewalWorks(int numThreads, int maxCallsPerSession)
// complete it, we will get a session lock
// lost exception. We are still able to verify
// that the message will be completed eventually.
var exception = (ServiceBusException)args.Exception;
if (!(args.Exception is ServiceBusException sbEx) ||
sbEx.Reason != ServiceBusFailureReason.SessionLockLost)
sbEx.Reason != ServiceBusFailureReason.SessionLockLost)
{
Assert.Fail(args.Exception.ToString());
}
Expand Down Expand Up @@ -1518,21 +1517,8 @@ public async Task MaxCallsPerSessionRespected(int numSessions, int maxConcurrent
ConcurrentDictionary<string, int> sessionDict = new ConcurrentDictionary<string, int>();

processor.ProcessMessageAsync += ProcessMessage;
processor.ProcessErrorAsync += args =>
{
// If the connection drops due to network flakiness
// after the message is received but before we
// complete it, we will get a session lock
// lost exception. We are still able to verify
// that the message will be completed eventually.
var exception = (ServiceBusException)args.Exception;
if (!(args.Exception is ServiceBusException sbEx) ||
sbEx.Reason != ServiceBusFailureReason.SessionLockLost)
{
Assert.Fail(args.Exception.ToString());
}
return Task.CompletedTask;
};
processor.ProcessErrorAsync += SessionErrorHandler;

await processor.StartProcessingAsync();

async Task ProcessMessage(ProcessSessionMessageEventArgs args)
Expand Down Expand Up @@ -1880,7 +1866,7 @@ Task ProcessMessage(ProcessSessionMessageEventArgs args)
}

processor.ProcessMessageAsync += ProcessMessage;
processor.ProcessErrorAsync += ExceptionHandler;
processor.ProcessErrorAsync += SessionErrorHandler;

await processor.StartProcessingAsync();
await tcs.Task;
Expand Down Expand Up @@ -1939,14 +1925,28 @@ async Task ProcessMessage(ProcessSessionMessageEventArgs args)
Assert.LessOrEqual(processor.InnerProcessor._tasks.Where(t => !t.Task.IsCompleted).Count(), 1);
}
}

processor.ProcessMessageAsync += ProcessMessage;
processor.ProcessErrorAsync += ExceptionHandler;
processor.ProcessErrorAsync += SessionErrorHandler;

await processor.StartProcessingAsync();
await tcs.Task;
await processor.StopProcessingAsync();
}
}

private Task SessionErrorHandler(ProcessErrorEventArgs args)
{
// If the connection drops due to network flakiness
// after the message is received but before we
// complete it, we will get a session lock
// lost exception. We are still able to verify
// that the message will be completed eventually.
if (args.Exception is not ServiceBusException { Reason: ServiceBusFailureReason.SessionLockLost })
{
Assert.Fail(args.Exception.ToString());
}
return Task.CompletedTask;
}
}
}