[servicebus] AttributeError: 'NoneType' object has no attribute 'client_ready_async' when reusing async ServiceBusSender objects #35618
Labels
Client
This issue points to a problem in the data-plane of the library.
customer-reported
Issues that are reported by GitHub users external to the Azure organization.
needs-team-attention
This issue needs attention from Azure service team or SDK team
question
The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Service Attention
This issue is responsible by Azure service team.
Service Bus
Describe the bug
Connections & sessions to service bus are extremely expensive to set up, taking 0.5~1.5s to initialize and teardown. Reusing the ServiceBusSender object mitigates this, but a race condition in the SDK connection flow causes exceptions:
To Reproduce
Steps to reproduce the behavior:
Expected behavior
async
SDKs should be async safe and throw no exceptions.Additional context
I've found the smoking gun for this bug. This bug is a race condition near line 222 in _servicebus_sender_async.py. Here's the relevant code:
Even though it seems impossible that
self._handler
would be None on theclient_ready_async
call since the previous line worked, because these are all async functions, there's a chance that other async code can unsetself._handler
elsewhere.The culprit is the if-check right at the top of that code block:
This calls up some superclass which unsets
self._handler
. When we're starting a connection, we have an indeterminate state whereself._running
is False, butself._handler
is True. If another parallel call comes into this code during the indeterminate state, it will disconnect the handler and null it out while the first call is still waiting in the while-loop.The text was updated successfully, but these errors were encountered: