Skip to content

Session Lock Expired with AutoLockRenew when message takes 4-5mn of processing #14699

Closed

Description

  • 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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.P0Service Buscustomer-reportedIssues that are reported by GitHub users external to the Azure organization.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions