Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Diagnose Azure service issues, query logs, and troubleshoot failures using GitHub Copilot for Azure
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
troubleshooting/messaging/azure-servicebus-dotnet.md
1# Azure Service Bus SDK — .NET (C#)23Package: `Azure.Messaging.ServiceBus` | [README](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/) | [Full Troubleshooting Guide](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/servicebus/Azure.Messaging.ServiceBus/TROUBLESHOOTING.md)45## Common Errors67| Exception | Reason | Fix |8|-----------|--------|-----|9| `ServiceBusException` (ServiceTimeout) | Service didn't respond | Transient — auto-retried. For session accept, means no unlocked sessions |10| `ServiceBusException` (MessageLockLost) | Lock expired or link detached | Renew lock, reduce processing time, check network |11| `ServiceBusException` (SessionLockLost) | Session lock expired | Re-accept session, renew lock before expiry |12| `ServiceBusException` (QuotaExceeded) | Too many concurrent receives | Reduce receivers or use batch receives |13| `ServiceBusException` (MessageSizeExceeded) | Message or batch too large | Reduce payload. Premium tier supports individual messages up to 100MB. Batch limit is artificially computed on the client from the max message size sent by the service, so batches can also be impacted |14| `ServiceBusException` (ServiceBusy) | Request throttled | Auto-retried with 10s backoff. See [throttling docs](https://learn.microsoft.com/azure/service-bus-messaging/service-bus-throttling) |15| `UnauthorizedAccessException` | Bad credentials | Verify connection string, SAS, or RBAC roles |1617## Exception Filtering1819```csharp20try { /* receive messages */ }21catch (ServiceBusException ex) when (ex.Reason == ServiceBusFailureReason.ServiceTimeout)22{23// Handle timeout24}25```2627## Key Issues2829- **Socket exhaustion**: Treat `ServiceBusClient` as singleton. Each creates a new AMQP connection. Always call `CloseAsync`/`DisposeAsync`.30- **Lock lost before expiry**: Can happen on link detach (transient network) or 10-min idle timeout.31- **Processor high concurrency**: May cause hangs with extreme concurrency settings. Test with moderate values.32- **Session processor slow switching**: Tune `SessionIdleTimeout` to reduce wait time between sessions.33- **Batch size limits**: Batch limit is artificially computed on the client from the max message size sent by the service. Send large messages individually if batch creation fails.34- **Transactions across entities**: Requires all entities on same namespace. Use `ServiceBusClient.CreateSender` with `via` entity support.35- **WebSockets**: Use `ServiceBusTransportType.AmqpWebSockets` when AMQP ports (5761, 5762) are blocked.36