0

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

1 Answers1

1

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.

Community
  • 1
  • 1
sel-fish
  • 4,308
  • 2
  • 20
  • 39
  • I'm sorry, I don't fully understand. Is the implication that my use of the locks is incorrect? If so please elaborate. – a_river_in_canada Jun 29 '16 at 14:43
  • almost right, but something needs your attention. If 'self.client.write' throw exception in your code (just a 'if'), your code will not call ```lock.release()```, which will leave a key in etcd. then the next time you want to lock, it will just wait...the timeout argument seems not work under that condition... – sel-fish Jun 29 '16 at 14:48