I am writing a plugin for Ida (in python) that utilizes the Etcd remote key value storage system. My problem is that when I attempt to get a lock on the server
lock = etcd.Lock(self.client, 'ida_lock')
Should timeout after 30 seconds. Hopefully that is enough.
lock.acquire(blocking=True,lock_ttl=None,timeout=30)
if lock.is_acquired:
data,idc_file = self.get_idc_data()
if os.path.isfile('expendable.idc'):
self.client.write('/fREd/' + self.md5 + '/all/', idc_file, prevValue = open('expendable.idc','r').readlines())
else:
self.client.write('/fREd/' + self.md5 + '/all/', idc_file)
lock.release()
like so, Ida freezes and I was wondering if anyone had any insight on why this is happening or how to fix it.
So for reference the method that includes this is called via a keyboard shortcut
idaapi.add_hotkey('Ctrl-.', self.push_data)
and there is no doubt that it is the lock that causes the problem.
You can look at the python-etcd source at https://github.com/jplana/python-etcd
There are keys already exist under the directory /_locks/ida_lock
.
To list the files under /_locks/ida_lock
:
etcdctl ls /_locks/ida_lock
To rescue yourself from this, run :
etcdctl rm /_locks/ida_lock --dir --recursive
To avoid this situation, you may run lock.release()
in the finally
block as if you don't release, there will be a file remained under /_locks/ida_lock
.
Further more, you can add some logging configs (which you can reference here) to dig more when dealing with this kind of problems.