Handle cleanup does not handle exceptions correctly
Reproduction
To reproduce with the following script, first mkdir ./syncdb
.
import pyalpm
handle = pyalpm.Handle("/", "./syncdb")
t = handle.init_transaction()
raise Exception("yo, this is broken.")
Output
(venv) { kevr@volcano builddir } > python pyalpmcrash.py git:kevr/master [134]
Traceback (most recent call last):
File "/home/kevr/dev/pacman/builddir/pyalpmcrash.py", line 5, in <module>
raise Exception("yo, this is broken.")
Exception: yo, this is broken.
Exception ignored in tp_clear of: <class 'dict'>
alpm.error: ('unable to release alpm handle',)
Workaround
A workaround is to use a try/catch block around anything that can cause an exception during a transaction. If this is intended, it should be documented somewhere:
import pyalpm
handle = pyalpm.Handle("/", "./syncdb")
t = handle.init_transaction()
try:
raise Exception("yo")
except Exception as exc:
print(f"error: {str(exc)}")
t.release()
Pacman Patch (fix to this immediate problem)
https://lists.archlinux.org/pipermail/pacman-dev/2021-November/025401.html
However, this does not fix the real issue at hand. In any case, we should not have more than one exception raised per code path, which is what's causing this.