Open iangoldby opened 3 months ago
As a side-note, if you are not supposed to be able to use the same ServiceBusSender concurrently in different tasks then it would be helpful if that were made unmissable in the documentation.
Hi @iangoldby, the Servicebus library is not concurrent safe and as such is not meant to be used like that. The recommended approach would be to use an asyncio.Lock around the sender.
I do agree we need to make it more prominent ( with examples ) in our documentation and bring it up in to view compared to where it is today
@kashifkhan Thanks for your response and I'm glad you agree that the documentation would benefit from improving. In particular, I think it is fair to say that most developers would not expect a warning about thread safety also to apply to async code. A lot of developers would regard the async world as an escape from thread concurrency problems :-).
Describe the bug Sending multiple messages on the Service Bus concurrently using the same asyncio sender results in the handler shutting down, leading ultimately to
ServiceBusError: Handler failed: 'NoneType' object has no attribute 'create_sender_link'.
To Reproduce
This results in (usually) two messages being successfully queued, and the following traceback:
Expected behavior Ten messages sent to the queue and no errors.
Additional context Note that this is just a minimal example to reproduce the issue. The real application where I needed to make concurrent requests with asyncio.gather() was an RPC application with session_id.
I have also noticed that if I use an asyncio.Lock() to prevent the sender.send_messages() requests running concurrently then the problem is not exhibited.