freebsd / pkg

Package management tool for FreeBSD. Help at #pkg on Libera Chat or pkg@FreeBSD.org
Other
748 stars 279 forks source link

/var/cache/pkg should be locked while fetching occurs #1774

Open yurivict opened 5 years ago

yurivict commented 5 years ago

Currently locking is done based on /var/db/pkg. However, /var/db/pkg and /var/cache/pkg contain different types of information. Package databases may be separate (for example, in different jails), but cache may be shared between them to reduce network downloads.

In such case the errors like this occur:

[4/153] Fetching nvidia-driver-390.87_3.txz: 100%   89 MiB   4.7MB/s    00:20    
pkg: cached package nvidia-driver-390.87_3: size mismatch, cannot continue
failed to install the requested packages into the jail: the command failed with the exit status 768
danfe commented 4 years ago

Actually, I don't understand why any locking is needed during the fetch phase. With my typical download speeds (~20-100kB/s) it's really a PITA to do any other work on ports (e.g. running portupgrade) while fetching packages because of this.

Feel free to briefly obtain the lock and verify that nothing bad had happened after the download, but please do not hold the lock while download is in progress. It's generally considered bad practice to hold locks for arbitrarily long periods of time.

yurivict commented 4 years ago

Actually, I don't understand why any locking is needed during the fetch phase.

Because 2 or more different processes would be fetching the same file at the same time and conflict with each other. Currently it's only pkg and it locks the other directory, but pkg can be run from jail that shares /var/cache/pkg with the host system.