Skip to content

Commit bafbcb2

Browse files
Copilotswathipil
andcommitted
Fix TROUBLESHOOTING.md formatting and content issues based on review feedback
Co-authored-by: swathipil <[email protected]>
1 parent 6df3eb4 commit bafbcb2

File tree

1 file changed

+50
-178
lines changed

1 file changed

+50
-178
lines changed

sdk/servicebus/azure-servicebus/TROUBLESHOOTING.md

Lines changed: 50 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,15 @@ This troubleshooting guide contains instructions to diagnose frequently encounte
3838

3939
## General troubleshooting
4040

41-
Azure Service Bus client library will raise exceptions defined in [Azure Core](https://aka.ms/azsdk/python/core/docs#module-azure.core.exceptions) and [azure.servicebus.exceptions](https://docs.microsoft.com/python/api/azure-servicebus/azure.servicebus.exceptions).
41+
Azure Service Bus client library will raise exceptions defined in [Azure Core](https://aka.ms/azsdk/python/core/docs#module-azure.core.exceptions) and Service Bus-specific exceptions in `azure.servicebus.exceptions`.
4242

4343
### Enable client logging
4444

4545
This library uses the standard [logging](https://docs.python.org/3/library/logging.html) library for logging.
4646

47-
Basic information about HTTP sessions (URLs, headers, etc.) is logged at `INFO` level.
47+
Basic information about AMQP operations (connections, links, etc.) is logged at `INFO` level.
4848

49-
Detailed `DEBUG` level logging, including request/response bodies and **unredacted** headers, can be enabled on the client or per-operation with the `logging_enable` keyword argument.
49+
Detailed `DEBUG` level logging, including AMQP frame tracing and **unredacted** headers, can be enabled on the client or per-operation with the `logging_enable` keyword argument.
5050

5151
To enable client logging and AMQP frame level trace:
5252

@@ -73,81 +73,42 @@ See full Python SDK logging documentation with examples [here](https://learn.mic
7373

7474
### Common exceptions
7575

76-
The Service Bus APIs generate the following exceptions in `azure.servicebus.exceptions`:
76+
The Service Bus client library raises the following exceptions defined in `azure.servicebus.exceptions`:
7777

7878
#### Connection and Authentication Exceptions
7979

80-
- **ServiceBusConnectionError:** An error occurred in the connection to the service. This may have been caused by a transient network issue or service problem. It is recommended to retry.
81-
82-
- **ServiceBusAuthenticationError:** An error occurred when authenticating the connection to the service. This may have been caused by the credentials being incorrect. It is recommended to check the credentials.
83-
84-
- **ServiceBusAuthorizationError:** An error occurred when authorizing the connection to the service. This may have been caused by the credentials not having the right permission to perform the operation. It is recommended to check the permission of the credentials.
80+
- **ServiceBusConnectionError:** Connection to the service failed. Check network connectivity and retry.
81+
- **ServiceBusAuthenticationError:** Authentication failed. Verify credentials are correct.
82+
- **ServiceBusAuthorizationError:** Authorization failed. Check that credentials have the required permissions.
8583

8684
#### Operation and Timeout Exceptions
8785

88-
- **OperationTimeoutError:** This indicates that the service did not respond to an operation within the expected amount of time. This may have been caused by a transient network issue or service problem. The service may or may not have successfully completed the request; the status is not known. It is recommended to attempt to verify the current state and retry if necessary.
89-
90-
- **ServiceBusCommunicationError:** Client isn't able to establish a connection to Service Bus. Make sure the supplied host name is correct and the host is reachable. If your code runs in an environment with a firewall/proxy, ensure that the traffic to the Service Bus domain/IP address and ports isn't blocked. For information about required ports, see [What ports do I need to open on the firewall?](https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-faq#what-ports-do-i-need-to-open-on-the-firewall--).
86+
- **OperationTimeoutError:** Service did not respond within the expected time. Retry the operation.
87+
- **ServiceBusCommunicationError:** Unable to establish connection to Service Bus. Check network connectivity and firewall settings. For firewall configuration, see [What ports do I need to open on the firewall?](https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-faq#what-ports-do-i-need-to-open-on-the-firewall--).
9188

9289
#### Message Handling Exceptions
9390

94-
- **MessageSizeExceededError:** This indicates that the message content is larger than the service bus frame size. This could happen when too many service bus messages are sent in a batch or the content passed into the body of a `Message` is too large. It is recommended to reduce the count of messages being sent in a batch or the size of content being passed into a single `ServiceBusMessage`.
95-
96-
- **MessageAlreadySettled:** This indicates failure to settle the message. This could happen when trying to settle an already-settled message.
97-
98-
- **MessageLockLostError:** The lock on the message has expired and it has been released back to the queue. It will need to be received again in order to settle it. You should be aware of the lock duration of a message and keep renewing the lock before expiration in case of long processing time. `AutoLockRenewer` could help on keeping the lock of the message automatically renewed.
99-
100-
- **MessageNotFoundError:** Attempt to receive a message with a particular sequence number. This message isn't found. Make sure the message hasn't been received already. Check the deadletter queue to see if the message has been deadlettered.
91+
- **MessageSizeExceededError:** Message content exceeds size limits. Reduce message size or batch count.
92+
- **MessageAlreadySettled:** Attempt to settle an already-settled message.
93+
- **MessageLockLostError:** Message lock expired. Use `AutoLockRenewer` or process messages faster.
94+
- **MessageNotFoundError:** Message with specified sequence number not found. Check if message was already processed.
10195

10296
#### Session Handling Exceptions
10397

104-
- **SessionLockLostError:** The lock on the session has expired. All unsettled messages that have been received can no longer be settled. It is recommended to reconnect to the session if receive messages again if necessary. You should be aware of the lock duration of a session and keep renewing the lock before expiration in case of long processing time. `AutoLockRenewer` could help on keeping the lock of the session automatically renewed.
105-
106-
- **SessionCannotBeLockedError:** Attempt to connect to a session with a specific session ID, but the session is currently locked by another client. Make sure the session is unlocked by other clients.
98+
- **SessionLockLostError:** Session lock expired. Reconnect to the session or use `AutoLockRenewer`.
99+
- **SessionCannotBeLockedError:** Session is locked by another client. Wait for lock to expire.
107100

108101
#### Service and Entity Exceptions
109102

110-
- **ServiceBusQuotaExceededError:** The messaging entity has reached its maximum allowable size, or the maximum number of connections to a namespace has been exceeded. Create space in the entity by receiving messages from the entity or its subqueues.
111-
112-
- **ServiceBusServerBusyError:** Service isn't able to process the request at this time. Client can wait for a period of time, then retry the operation.
113-
114-
- **MessagingEntityNotFoundError:** Entity associated with the operation doesn't exist or it has been deleted. Please make sure the entity exists.
115-
116-
- **MessagingEntityDisabledError:** Request for a runtime operation on a disabled entity. Please activate the entity.
103+
- **ServiceBusQuotaExceededError:** Entity has reached maximum size or connection limit. Create space by receiving messages.
104+
- **ServiceBusServerBusyError:** Service is temporarily overloaded. Implement exponential backoff retry.
105+
- **MessagingEntityNotFoundError:** Entity does not exist or has been deleted.
106+
- **MessagingEntityDisabledError:** Entity is disabled. Enable the entity to perform operations.
117107

118108
#### Auto Lock Renewal Exceptions
119109

120-
- **AutoLockRenewFailed:** An attempt to renew a lock on a message or session in the background has failed. This could happen when the receiver used by `AutoLockRenewer` is closed or the lock of the renewable has expired. It is recommended to re-register the renewable message or session by receiving the message or connect to the sessionful entity again.
121-
122-
- **AutoLockRenewTimeout:** The time allocated to renew the message or session lock has elapsed. You could re-register the object that wants be auto lock renewed or extend the timeout in advance.
123-
124-
#### Python-Specific Considerations
125-
126-
- **ImportError/ModuleNotFoundError:** Common when Azure Service Bus dependencies are not properly installed. Ensure you have installed the correct package version:
127-
```bash
128-
pip install azure-servicebus
129-
```
130-
131-
- **TypeError:** Often occurs when passing incorrect data types to Service Bus methods:
132-
```python
133-
# Incorrect: passing string instead of ServiceBusMessage
134-
sender.send_messages("Hello World") # This will fail
135-
136-
# Correct: create ServiceBusMessage objects
137-
from azure.servicebus import ServiceBusMessage
138-
message = ServiceBusMessage("Hello World")
139-
sender.send_messages(message)
140-
```
141-
142-
- **ConnectionError/socket.gaierror:** Network-level errors that may require checking DNS resolution and network connectivity:
143-
```python
144-
import socket
145-
try:
146-
# Test DNS resolution
147-
socket.gethostbyname("your-namespace.servicebus.windows.net")
148-
except socket.gaierror as e:
149-
print(f"DNS resolution failed: {e}")
150-
```
110+
- **AutoLockRenewFailed:** Lock renewal failed. Re-register the renewable message or session.
111+
- **AutoLockRenewTimeout:** Lock renewal timeout exceeded. Extend timeout or re-register the object.
151112

152113
### Timeouts
153114

@@ -425,140 +386,53 @@ with receiver:
425386

426387
### Number of messages returned doesn't match number requested
427388

428-
When attempting to receive multiple messages using `receive_messages()` with `max_message_count` greater than 1, you're not guaranteed to receive the exact number requested.
429-
430-
**Why this happens:**
431-
- Service Bus optimizes for throughput and latency
432-
- After the first message is received, the receiver waits only a short time (typically 20ms) for additional messages
433-
- The `max_wait_time` controls how long to wait for the **first** message, not subsequent ones
434-
435-
**Resolution:**
436-
1. **Don't assume all available messages will be received in one call:**
437-
```python
438-
import time
439-
from azure.servicebus.exceptions import MessagingEntityNotFoundError, MessagingEntityDisabledError
440-
441-
def receive_all_available_messages(receiver, total_expected=None):
442-
"""Receive all available messages from a queue/subscription"""
443-
all_messages = []
444-
445-
while True:
446-
# Receive in batches
447-
messages = receiver.receive_messages(max_message_count=10, max_wait_time=5)
448-
449-
if not messages:
450-
break # No more messages available
451-
452-
all_messages.extend(messages)
453-
454-
# Process messages immediately to avoid lock expiration
455-
for message in messages:
456-
try:
457-
# Process message logic here
458-
print(f"Processing: {message}")
459-
receiver.complete_message(message)
460-
except Exception as e:
461-
print(f"Error processing message: {e}")
462-
receiver.abandon_message(message)
463-
464-
return all_messages
465-
```
466-
467-
2. **Use continuous receiving for stream processing:**
468-
```python
469-
import time
389+
When calling `receive_messages()` with `max_message_count` > 1, you may receive fewer messages than requested.
470390

471-
def continuous_message_processing(receiver):
472-
"""Continuously process messages as they arrive"""
473-
while True:
474-
try:
475-
messages = receiver.receive_messages(max_message_count=1, max_wait_time=60)
476-
477-
for message in messages:
478-
# Process immediately
479-
try:
480-
process_message(message)
481-
receiver.complete_message(message)
482-
except Exception as e:
483-
print(f"Processing failed: {e}")
484-
receiver.abandon_message(message)
485-
486-
except KeyboardInterrupt:
487-
break
488-
except Exception as e:
489-
print(f"Receive error: {e}")
490-
time.sleep(5) # Brief pause before retry
491-
```
492-
493-
### Messages not being received
494-
495-
Messages might not be received due to various configuration or state issues.
391+
**Cause:** Service Bus waits briefly (20ms) for additional messages after the first. `max_wait_time` only applies to the first message.
496392

497-
**Common causes and resolutions:**
393+
**Resolution:** Call `receive_messages()` in a loop to get all available messages:
498394

499-
1. **Check entity state:**
500395
```python
501-
# Verify the queue/subscription exists and is active
502-
try:
503-
# This will fail if entity doesn't exist
504-
receiver = client.get_queue_receiver(queue_name)
505-
messages = receiver.receive_messages(max_message_count=1, max_wait_time=5)
506-
396+
all_messages = []
397+
while True:
398+
messages = receiver.receive_messages(max_message_count=10, max_wait_time=5)
507399
if not messages:
508-
print("No messages available - check if messages are being sent")
509-
510-
except MessagingEntityNotFoundError:
511-
print("Queue/subscription does not exist")
512-
except MessagingEntityDisabledError:
513-
print("Queue/subscription is disabled")
400+
break
401+
all_messages.extend(messages)
402+
for message in messages:
403+
receiver.complete_message(message)
514404
```
515405

516-
2. **Verify message filters (for subscriptions):**
517-
```python
518-
# For topic subscriptions, check if messages match subscription filters
519-
from azure.servicebus.management import ServiceBusAdministrationClient
520-
521-
admin_client = ServiceBusAdministrationClient.from_connection_string(connection_string)
522-
523-
# Check subscription rules
524-
rules = admin_client.list_rules(topic_name, subscription_name)
525-
for rule in rules:
526-
print(f"Rule: {rule.name}, Filter: {rule.filter}")
527-
```
406+
### Messages not being received
528407

529-
3. **Check for competing consumers:**
530-
```python
531-
# Multiple receivers on the same queue will compete for messages
532-
# Ensure this is intended behavior or use topic/subscription pattern
408+
**Common causes:**
409+
- Entity doesn't exist or is disabled
410+
- No messages in the queue/subscription
411+
- Message filters excluding messages (subscriptions)
412+
- Lock duration too short
533413

534-
# For debugging, temporarily use peek to see if messages exist
535-
messages = receiver.peek_messages(max_message_count=10)
536-
print(f"Found {len(messages)} messages in queue without receiving them")
537-
```
414+
**Resolution:**
415+
1. Verify entity exists: `ServiceBusAdministrationClient.get_queue()` or `get_subscription()`
416+
2. Check entity is enabled
417+
3. For subscriptions, verify filter rules allow your messages
418+
4. Increase `max_wait_time` or check message count
538419

539420
### Dead letter queue issues
540421

541-
Messages can be moved to the dead letter queue for various reasons:
542-
543-
**Common reasons:**
544-
- Message TTL expired
545-
- Max delivery count exceeded
546-
- Message was explicitly dead lettered
547-
- Message processing failed repeatedly
422+
Messages move to the dead letter queue due to TTL expiration, max delivery count exceeded, or explicit dead lettering.
548423

549-
**Debugging dead letter messages:**
424+
**Resolution:**
550425
```python
551-
# Receive from dead letter queue
552-
dlq_receiver = servicebus_client.get_queue_receiver(
426+
# Access dead letter queue to inspect messages
427+
dlq_receiver = client.get_queue_receiver(
553428
queue_name="your_queue",
554429
sub_queue=ServiceBusSubQueue.DEAD_LETTER
555430
)
556431

557-
with dlq_receiver:
558-
messages = dlq_receiver.receive_messages(max_message_count=10)
559-
for message in messages:
560-
print(f"Dead letter reason: {message.dead_letter_reason}")
561-
print(f"Dead letter description: {message.dead_letter_error_description}")
432+
messages = dlq_receiver.receive_messages(max_message_count=10)
433+
for message in messages:
434+
print(f"Reason: {message.dead_letter_reason}")
435+
print(f"Description: {message.dead_letter_error_description}")
562436
```
563437

564438
### Mixing sync and async code
@@ -731,5 +605,3 @@ When filing GitHub issues for Service Bus, please include:
731605
5. **Error details:** Complete exception stack trace and error messages
732606

733607
The more information provided, the faster we can help resolve your issue.
734-
735-
Please view the [exceptions reference docs](https://docs.microsoft.com/python/api/azure-servicebus/azure.servicebus.exceptions) for detailed descriptions of our common Exception types.

0 commit comments

Comments
 (0)