Why am I getting "The lock supplied is invalid." error when I am trying to delete queue message using LockTocken
Asked Answered
C

3

6

I am using python langauge to send & receive messages using Azure bus service queue.

I am getting "The lock supplied is invalid.Either the lock expired, or the message has already been removed from the queue" when deleting message from queue using below code.

sbs.delete_queue_message('taskqueue',5,'ef4e2189-bfef-42ac-ba09-7fd20287f6a9') sbs.delete_queue_message('taskqueue','SequenceNumber','LockToken')

from azure.servicebus.control_client import ServiceBusService, Message, Topic, Rule, DEFAULT_RULE_NAME
key_name = '###############' # SharedAccessKeyName from Azure portal
key_value = '####################' # SharedAccessKey from Azure portal
service_namespace = '###########'
sbs  = ServiceBusService(service_namespace,shared_access_key_name=key_name,shared_access_key_value=key_value)      


msg = sbs.receive_queue_message('taskqueue')
sbs.delete_queue_message('taskqueue',5,'ef4e2189-bfef-42ac-ba09-7fd20287f6a9')
Chiropractic answered 19/6, 2019 at 10:4 Comment(2)
From where're you getting this lock token (ef4e2189-bfef-42ac-ba09-7fd20287f6a9) value?Basiliabasilian
Using msg.broker_properties['LockToken'])Chiropractic
C
5

Finally able to solve above issue by increasing lock duration from default to 300 seconds from web portal.

After increasing lock duration I am able to successfully run my project without any kind of lock related errors.

Chiropractic answered 25/9, 2019 at 8:31 Comment(0)
S
4

The lock can expire if the message is processed longer than the MaxLockDuration specified for the queue. Check what value for taskqueue queue is and what's the duration of your message processing since the moment you've received it and till invocation of delete_queue_message().

An additional consideration is prefetch, but I'm not sure if it's enabled for the Python client or not. Worth verifying that it's either set to zero or is not causing messages to lose locks while waiting for processing.

Stephaniestephannie answered 19/6, 2019 at 20:41 Comment(2)
Thank you @Sean Feldman for you answer I have checked about it & found that Locktoken expire after every every 60 seconds.So Is there any way to increase those time or set more time for LockToken.Chiropractic
Yes, there is. You can set MaxLockDuration up to 5 minutes. You will need to use either the portal or a tool to do so. ServiceBus Explorer, Queue Explorer, or Cerebrate Cerulean.Stephaniestephannie
V
0

Try increasing lock_duration.

Once it's done, here's the codce in v7 of servicebus https://pypi.org/project/azure-servicebus/7.0.0/

https://github.com/Azure/azure-sdk-for-python/blob/master/sdk/servicebus/azure-servicebus/samples/sync_samples/receive_queue.py

Visayan answered 10/1, 2021 at 21:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.