Description
openedon Oct 22, 2020
- azure-servicebus 0.50.3
- Debian 10
- Python 3.8
Describe the bug
I am using the AutoLockRenew and get a Session lock expired
when the message takes a around 5 mn to process. The exception happens on calling complete()
on the message.
I feel like this is more or less related to #11611, #12307, and #12937, but to be honest I fail to understand the whole of it and how to apply it to my case. I don't know if it might be linked or not also to another issue of mine, #9402.
I think maybe I am failing to understand how all timeout/duration properties are supposed to work together : the lock duration of the subscription, the receiver
timeout, the AutoLockRenewtimeout
, and the fetch_next
timeout.
First, on the Service Bus side, in the portal, my subscription has sessions enabled, with a TTL of 30mn and a lock duration of 5mn.
Then, my code to handle messages is the following :
sub_client = self._bus_client.get_subscription(_topic, _sub)
receiver = sub_client.get_receiver(mode=ReceiveSettleMode.PeekLock,
session=(session_id or NEXT_AVAILABLE), idle_timeout=1)
locker = AutoLockRenew(max_workers=1)
try:
sub_client: SubscriptionClient
receiver: Receiver
messages: List[Message] = receiver.fetch_next(max_batch_size=1, timeout=1)
if messages:
message = messages[0]
# Beware, for session-enabled stuff, the Autolock has to be on the receiver, not the message
locker.register(receiver, timeout=24*3600)
self._handle_message(message, handler)
return message
except NoActiveSession:
return
finally:
locker.shutdown(wait=False)
receiver.close()
Note : self._handle_message
is basically a try: ... msg.complete() except: msg.abandon()
with some logging and verifications on message properties.
When this executes for short processing, it is fine, but I have a processing that can be a bit long and when it takes 6 minutes, I get the following :
Session lock expired
Traceback (most recent call last):
File "/app/***/common/services/bus/***.py", line 226, in _handle_message
msg.complete()
File "/usr/local/lib/python3.8/site-packages/azure/servicebus/common/message.py", line 329, in complete
self._is_live('complete')
File "/usr/local/lib/python3.8/site-packages/azure/servicebus/common/message.py", line 105, in _is_live
raise SessionLockExpired(inner_exception=self._receiver.auto_renew_error)
azure.servicebus.common.errors.SessionLockExpired: Session lock expired
Thank you !