Skip to content

Conversation

@Rtoax
Copy link

@Rtoax Rtoax commented Sep 22, 2025

When dnf-install is killed or exited abnormally, a PID will remain in the rpmdb_lock.pid, and when the system runs for a period of time, the PID will be reused, and at this time, the command will be stuck when the dnf operation (such as dnf install) is performed again. Therefore, it is not sufficient to detect whether the PID exists, and the creation time of rpmdb_lock.pid needs to be later than the startup time of pid=PID process is to solve this problem.

How to reproduce:

terminal 1: write a bad pid to lock file

$ echo 1 | sudo tee /var/lib/dnf/rpmdb_lock.pid

terminal 2: try install rpm to access rpmdb_lock.pid file

$ sudo dnf reinstall dnf

Before this patch, the dnf-reinstall will 'Waiting for process 1', after this commit, the dnf-reinstall will continue to running, because pid=1 is bad pid, it's belongs to systemd.

Add depends python3-psutil.

When dnf-install is killed or exited abnormally, a PID will remain in the
rpmdb_lock.pid, and when the system runs for a period of time, the PID will
be reused, and at this time, the command will be stuck when the dnf operation
(such as dnf install) is performed again. Therefore, it is not sufficient to
detect whether the PID exists, and the creation time of rpmdb_lock.pid needs
to be later than the startup time of pid=PID process is to solve this problem.

How to reproduce:

terminal 1: write a bad pid to lock file

    $ echo 1 | sudo tee /var/lib/dnf/rpmdb_lock.pid

terminal 2: try install rpm to access rpmdb_lock.pid file

    $ sudo dnf reinstall dnf

Before this patch, the dnf-reinstall will 'Waiting for process 1', after
this commit, the dnf-reinstall will continue to running, because pid=1
is bad pid, it's belongs to systemd.

Add depends python3-psutil.

Signed-off-by: Ge Changzhong <[email protected]>
Signed-off-by: Rong Tao <[email protected]>
Signed-off-by: Li Peng <[email protected]>
@Rtoax Rtoax requested a review from a team as a code owner September 22, 2025 09:09
@Rtoax Rtoax requested review from fhbash and removed request for a team September 22, 2025 09:09
@ppisar
Copy link
Contributor

ppisar commented Sep 26, 2025

Besides the tests fail now:

+ /usr/bin/ctest --test-dir redhat-linux-build --output-on-failure --force-new-ctest-process -j4 -VV
[...]
1:   File "/builddir/build/BUILD/dnf-4.24.0-build/dnf-4.24.0/dnf/lock.py", line 33, in <module>
1:     import psutil
1: ModuleNotFoundError: No module named 'psutil'

(you need to specify the new RPM dependency on psutil Python3 module)

I don't think this is a good approach. If something shifts the system clock, the test will be broken.

Rather simply try locking the PID file. If acquiring the lock fails, it means it's already locked by a running process. File locks are automatically removed when a process terminates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants