[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#922416: cache.commit() doesn't release the archives lock



Package: python-apt
Version: 1.8.3

Hi!

I have tools that use python-apt to interact with the system. Until recently I was using an old version of python-apt (1.4.0~beta3) and it was working fine.  I'm now migrating to the latest version (1.8.3) and I've encountered a problem with it.

When testing this version, I found a problem that seems to be related to the changes in locking.  The code that's failing is using the cache, calling cache.commit and after that's done, calling another command via subprocess that also interacts with apt.  The problem that I'm encountering is that this other command can't acquire the archives lock.

Following the code, I've realized that while the commit() function acquires a lock [1] (by calling get_lock on the Acquire object), it never actually releases this lock.

From my understanding of the C++ code, the lock is released when the object is garbage collected [2] and calling shutdown (which is what the commit() code does) is not enough.

The cache.update() function code is quite different in this regard.  It obtains and releases the code explicitly, instead of relying on the Acquire object [3]. I don't know if there's a reason behind these two different locking behaviors, but it seems to me that the commit one is wrong and it would be better to make it acquire and release the lock locally instead of relying on the Acquire object being garbage collected

[1] https://salsa.debian.org/apt-team/python-apt/blob/master/apt/cache.py#L623
[2] https://salsa.debian.org/apt-team/apt/blob/master/apt-pkg/acquire.cc#L192
[3] https://salsa.debian.org/apt-team/python-apt/blob/master/apt/cache.py#L555

I've found that opening and closing the file after calling commit() fixes the issue for me, so I'm pretty sure that there's a problem is that commit() leaving that file locked.

Please let me know if there's something I'm missing or that I'm somehow doing wrong.  Thanks!
--
Cheers,
Marga

Reply to: