Large numbers of Timeout Exceptions from Service Bus

Neil Sorensen 20 Reputation points

We're starting to use Service Bus, and we've seen some large spikes of System.TimeoutExceptions. For example, we have one application that's consuming from ~10 subscriptions, and each instance recorded 411 System.TimeoutExceptions with a message saying The operation did not complete within the allocated time 00:00:05 for object receiver###. (ServiceTimeout) over the course of ~3 seconds.

I understand that networking is messy, and temporary interruptions will happen. My concern is that because of the number of exceptions that we're getting, we're getting alerts for issues that are already resolved by the time we can look. Is there a way to limit or supress these exceptions so our automated alerts won't be triggered? The stack trace for the exception doesn't include any of our code.

0 comments No comments

Sign in to comment

Answer accepted by question author

Rakesh Mishra 9,700 Reputation points Microsoft External Staff Moderator

Hello Neil,

Since you mentioned that "The stack trace for the exception doesn't include any of our code", it's highly likely you are using the background message processor provided by the SDK (such as ServiceBusProcessor in the Azure.Messaging.ServiceBus package, or RegisterMessageHandler in the older Microsoft.Azure.ServiceBus package) rather than a manual ReceiveMessageAsync loop.

When using these event-driven processors, the SDK continuously polls the broker for new messages in the background. If a polling request waits for the duration of the configured timeout and doesn't receive a message (or experiences a brief network hiccup), it throws a TimeoutException. The SDK safely catches this internally, passes it to the configured error handler, and automatically retries.

To prevent these transient polling timeouts from triggering your automated alerts, you should intercept and filter them out inside the central error handler callback that you provide to the SDK.

Here is how you can suppress these specific exceptions based on the SDK you are using:

  1. If using the newer Azure.Messaging.ServiceBus SDK:
    When configuring your ServiceBusProcessor, you register a ProcessErrorAsync handler. Inside this handler, you can check if the exception is a transient timeout and safely ignore it.
     processor.ProcessErrorAsync += ErrorHandler;
     Task ErrorHandler(ProcessErrorEventArgs args)
     {
     // Filter out transient timeouts so they don't trigger alerts
     if (args.Exception is ServiceBusException sbEx && sbEx.Reason == ServiceBusFailureReason.ServiceTimeout)
     {
     // Transient – log as Trace/Debug instead of Error, or ignore completely
     return Task.CompletedTask;
     }
     
     if (args.Exception is TimeoutException)
     {
     return Task.CompletedTask;
     }
     // Log actual critical errors to your alerting/APM system here
     // ...
     
     return Task.CompletedTask;
     }
    
  2. If using the older Microsoft.Azure.ServiceBus SDK:
    When calling RegisterMessageHandler, you configure a MessageHandlerOptions object containing an ExceptionReceivedHandler.
     var options = new MessageHandlerOptions(ExceptionReceivedHandler);
     subscriptionClient.RegisterMessageHandler(ProcessMessagesAsync, options);
     Task ExceptionReceivedHandler(ExceptionReceivedEventArgs args)
     {
     // Filter out timeout exceptions
     if (args.Exception is ServiceBusTimeoutException || args.Exception is TimeoutException)
     {
     // Suppress alert
     return Task.CompletedTask;
     }
     // Log actual critical errors
     // ...
     return Task.CompletedTask;
     }
    
  3. Check your Timeout Configuration:
    The exception specifically mentions an allocated time of 00:00:05 (5 seconds). By default, Service Bus clients usually have a 60-second timeout. It's highly probable that someone explicitly configured the TryTimeout (new SDK) or OperationTimeout (old SDK) to 5 seconds. Increasing this timeout closer to the default of 60 seconds will drastically reduce the sheer volume of these exceptions, as the processor won't "give up" and log an error quite so aggressively during quiet periods. Reference Links:

Hope this helps clear out the noise in your monitoring rules and do let me know in comments if any further questions.

Note: This response is drafted with the help of AI systems.

0 comments No comments

Sign in to comment

0 additional answers

Sign in to answer

Your answer