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

Add extra logging for support case #1110

Draft
wants to merge 4 commits into
base: release-4.2
Choose a base branch
from
Draft
Changes from 3 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
17 changes: 17 additions & 0 deletions src/Transport/Receiving/MessagePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,35 @@ void UpdateProcessingCapacity(int maxConcurrency)

public async Task StopReceive(CancellationToken cancellationToken = default)
{
if (messageProcessingCancellationTokenSource is null)
{
// Receiver hasn't been started or is already stopped
return;
}

Logger.Debug("Registering cancellation token");
// Wiring up the stop token to trigger the cancellation token that is being
// used inside the message handling pipeline
await using var _ = cancellationToken
.Register(state => (state as CancellationTokenSource)?.Cancel(),
messageProcessingCancellationTokenSource,
useSynchronizationContext: false).ConfigureAwait(false);
Logger.Debug("Cancellation token registered.");


// Deliberately not passing the cancellation token forward in order to make sure
// the processor waits until all processing handlers have returned. This makes
// the code compliant to the previous version that uses manual receives and is aligned
// with how the cancellation token support was initially designed.
await processor.StopProcessingAsync(CancellationToken.None)
.ConfigureAwait(false);
Logger.Info("Processor stopped processing.");

try
{
await processor.CloseAsync(cancellationToken)
.ConfigureAwait(false);
Logger.Info("Processor closed successfully.");
}
catch (Exception ex) when (ex.IsCausedBy(cancellationToken))
{
Expand All @@ -224,12 +236,17 @@ await processor.CloseAsync(cancellationToken)

processor.ProcessErrorAsync -= OnProcessorError;
processor.ProcessMessageAsync -= OnProcessMessage;
Logger.Debug("Processor event handlers detached.");

await processor.DisposeAsync().ConfigureAwait(false);
Logger.Debug("Processor disposed.");

messageProcessingCancellationTokenSource?.Dispose();
messageProcessingCancellationTokenSource = null;
Logger.Debug("Message processing cancellation token source disposed.");

circuitBreaker?.Dispose();
Logger.Debug("Circuit breaker disposed.");
}

async Task ProcessMessage(ServiceBusReceivedMessage message,
Expand Down