Skip to content

Commit b684064

Browse files
Copilotswathipil
andcommitted
Remove threading and concurrency section - not Service Bus specific
Co-authored-by: swathipil <[email protected]>
1 parent eb640c5 commit b684064

File tree

1 file changed

+1
-78
lines changed

1 file changed

+1
-78
lines changed

sdk/servicebus/azure-servicebus/TROUBLESHOOTING.md

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ This troubleshooting guide contains instructions to diagnose frequently encounte
1212
* [Message and session handling exceptions](#message-and-session-handling-exceptions)
1313
* [Service and entity exceptions](#service-and-entity-exceptions)
1414
* [Auto lock renewal exceptions](#auto-lock-renewal-exceptions)
15-
* [Threading and concurrency issues](#threading-and-concurrency-issues)
16-
* [Thread safety limitations](#thread-safety-limitations)
15+
1716
* [Troubleshooting authentication and authorization issues](#troubleshooting-authentication-and-authorization-issues)
1817
* [Troubleshooting connectivity issues](#troubleshooting-connectivity-issues)
1918
* [Timeout when connecting to service](#timeout-when-connecting-to-service)
@@ -128,82 +127,6 @@ See the [Troubleshooting message handling issues](#troubleshooting-message-handl
128127

129128
See the [Troubleshooting message handling issues](#troubleshooting-message-handling-issues) to help troubleshoot AutoLockRenewer errors.
130129

131-
## Threading and concurrency issues
132-
133-
### Thread safety limitations
134-
135-
**Important:** We do not guarantee that the `ServiceBusClient`, `ServiceBusSender`, and `ServiceBusReceiver` are thread-safe or coroutine-safe. We do not recommend reusing these instances across threads or sharing them between coroutines.
136-
137-
The data model type, `ServiceBusMessageBatch` is not thread-safe or coroutine-safe. It should not be shared across threads nor used concurrently with client methods.
138-
139-
Using the same client instances across multiple threads or tasks without proper synchronization can lead to:
140-
141-
- Connection errors and unexpected exceptions
142-
- Message corruption or loss
143-
- Deadlocks and race conditions
144-
- Unpredictable behavior
145-
146-
It is up to the running application to use these classes in a concurrency-safe manner.
147-
148-
For scenarios requiring concurrent sending in asyncio applications, ensure proper coroutine-safety management using mechanisms like asyncio.Lock().
149-
150-
```python
151-
import asyncio
152-
from azure.servicebus.aio import ServiceBusClient
153-
from azure.servicebus import ServiceBusMessage
154-
from azure.identity.aio import DefaultAzureCredential
155-
156-
SERVICE_BUS_NAMESPACE = "<your-namespace>.servicebus.windows.net"
157-
QUEUE_NAME = "<your-queue-name>"
158-
159-
lock = asyncio.Lock()
160-
161-
async def send_batch(sender_id, sender):
162-
async with lock:
163-
messages = [ServiceBusMessage(f"Message {i} from sender {sender_id}") for i in range(10)]
164-
await sender.send_messages(messages)
165-
print(f"Sender {sender_id} sent messages.")
166-
167-
credential = DefaultAzureCredential()
168-
client = ServiceBusClient(fully_qualified_namespace=SERVICE_BUS_NAMESPACE, credential=credential)
169-
170-
async with client:
171-
sender = client.get_queue_sender(queue_name=QUEUE_NAME)
172-
async with sender:
173-
await asyncio.gather(*(send_batch(i, sender) for i in range(5)))
174-
```
175-
176-
For scenarios requiring concurrent sending from multiple threads, ensure proper thread-safety management using mechanisms like `threading.Lock()`.
177-
178-
> **NOTE:** Native async APIs should be used instead of running in a `ThreadPoolExecutor`, if possible.
179-
180-
```python
181-
import threading
182-
from concurrent.futures import ThreadPoolExecutor
183-
from azure.servicebus import ServiceBusClient, ServiceBusMessage
184-
from azure.identity import DefaultAzureCredential
185-
186-
SERVICE_BUS_NAMESPACE = "<your-namespace>.servicebus.windows.net"
187-
QUEUE_NAME = "<your-queue-name>"
188-
189-
lock = threading.Lock()
190-
191-
def send_batch(sender_id, sender):
192-
with lock:
193-
messages = [ServiceBusMessage(f"Message {i} from sender {sender_id}") for i in range(10)]
194-
sender.send_messages(messages)
195-
print(f"Sender {sender_id} sent messages.")
196-
197-
credential = DefaultAzureCredential()
198-
client = ServiceBusClient(fully_qualified_namespace=SERVICE_BUS_NAMESPACE, credential=credential)
199-
200-
with client:
201-
sender = client.get_queue_sender(queue_name=QUEUE_NAME)
202-
with sender:
203-
with ThreadPoolExecutor(max_workers=5) as executor:
204-
for i in range(5):
205-
executor.submit(send_batch, i, sender)
206-
```
207130

208131
## Troubleshooting authentication and authorization issues
209132

0 commit comments

Comments
 (0)