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

Pass cancellation token to Dequeue method, and rewrite comment #51794

Merged
merged 1 commit into from
Mar 11, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private async Task ProcessQueueAsync()
{
while (!_cancelSource.IsCancellationRequested)
{
var work = await _queue.DequeueAsync().ConfigureAwait(false);
var work = await _queue.DequeueAsync(_cancelSource.Token).ConfigureAwait(false);

// Record when the work item was been de-queued and the request context preparation started.
work.Metrics.RecordExecutionStart();
Expand Down Expand Up @@ -230,8 +230,10 @@ private async Task ProcessQueueAsync()
}
catch (OperationCanceledException e) when (e.CancellationToken == _cancelSource.Token)
Copy link
Member

Choose a reason for hiding this comment

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

💡 The other way to do this is:

Suggested change
catch (OperationCanceledException e) when (e.CancellationToken == _cancelSource.Token)
catch (OperationCanceledException) when (_cancelSource.IsCancellationRequested)

{
// If the queue is asked to shut down between the start of the while loop, and the Dequeue call
// we could end up here, but we don't want to report an error. The Shutdown call will take care of things.
// If cancellation occurs as a result of our token, then it was either because we cancelled it in the Shutdown
// method, if it happened during a mutating request, or because the queue was completed in the Shutdown method
// if it happened while waiting to dequeue the next item. Either way, we're already shutting down so we don't
// want to log it.
}
catch (Exception e) when (FatalError.ReportAndCatch(e))
{
Expand Down