On 10/11/23 12:08, Antoine Beaupré wrote:
(adding the collector author and python3-apt author in cc)

Thanks for looping me in, Antoine. I'm sorry to hear this is happening! I haven't had a chance to experiment with this yet, but I have a few preliminary thoughts to share after reading through the conversation.

By the way, Eric, sometimes I forget what good bug reports look like. Thanks for providing an example.

First of all, my primary use-case for this collector is to alert me of updates that need to be installed (e.g. security updates). In that context, operating on a stale cache would give me stale information, which one could argue is worse than no information. Once is probably fine, which is why that script silently proceeds if there is a problem updating the cache, but actually adding the ability to disable the cache update (as Daniel suggests as a potential solution) seems like it would be a footgun.

Second, I must admit I'm also rather flummoxed by this behavior. Earlier in the thread, Daniel said:

> I personally run this textfile collector on a Debian bookworm system,
> as well as apticron - so this is (I think) a similar scenario where
> two  independent processes are periodically updating the apt cache,
> and I  wondered whether that was wise or not

I don't claim to be an apt expert, but I believe apt uses locks to prevent the scenario where this would be problematic, no? You can't run two `apt update`s at the same time: one fails because it can't get the lock. Similarly, you can't run one `apt update` at the same time as this Python script:

import apt
cache = apt.cache.Cache()
cache.update()

The Python script uses the same lock, and fails the same way. You can't run two instances of that script ^ at the same time, either. This is why we catch the `apt.cache.LockFailedException` error in the script. If the deadlock is really happening on the `cache.update()` line, that feels like an apt bug. Obviously jak will know better.

One off-the-cuff idea is that we could probably use a custom apt config to run the checks on our own copy of the cache without interacting with the system's cache, but that will greatly complicate this script.

Anyway, I'll do some experimentation and see if I can develop some properly-formed thoughts.

Kyle

Reply via email to