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 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
13 changes: 12 additions & 1 deletion src/Transport/Receiving/MessagePump.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,23 +199,29 @@ void UpdateProcessingCapacity(int maxConcurrency)

public async Task StopReceive(CancellationToken cancellationToken = default)
{
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 +230,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 Expand Up @@ -330,4 +341,4 @@ AzureServiceBusTransportTransaction CreateTransaction(string incomingQueuePartit

public string ReceiveAddress { get; }
}
}
}