[PATCH] fix: release transaction lock before unregistering syncdbs
Signed-off-by: Kevin Morris <kevr@0cost.org> --- `alpm_unregister_all_syncdbs` errors out when a transaction is held. Since this function closes transactions as-is, moving this call below the transaction unlock step solves issues that `pyalpm` sees when it cleans up the handle. lib/libalpm/alpm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 6708e202..1c38feb8 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -107,10 +107,6 @@ int SYMEXPORT alpm_release(alpm_handle_t *myhandle) myhandle->db_local = NULL; } - if(alpm_unregister_all_syncdbs(myhandle) == -1) { - ret = -1; - } - #ifdef HAVE_LIBCURL curl_multi_cleanup(myhandle->curlm); curl_global_cleanup(); @@ -118,6 +114,11 @@ int SYMEXPORT alpm_release(alpm_handle_t *myhandle) #endif _alpm_handle_unlock(myhandle); + + if(alpm_unregister_all_syncdbs(myhandle) == -1) { + ret = -1; + } + _alpm_handle_free(myhandle); return ret; -- 2.34.0
On 11/19/21 at 09:09pm, Kevin Morris via pacman-dev wrote:
Signed-off-by: Kevin Morris <kevr@0cost.org> --- `alpm_unregister_all_syncdbs` errors out when a transaction is held. Since this function closes transactions as-is, moving this call below the transaction unlock step solves issues that `pyalpm` sees when it cleans up the handle.
lib/libalpm/alpm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 6708e202..1c38feb8 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -107,10 +107,6 @@ int SYMEXPORT alpm_release(alpm_handle_t *myhandle) myhandle->db_local = NULL; }
- if(alpm_unregister_all_syncdbs(myhandle) == -1) { - ret = -1; - } - #ifdef HAVE_LIBCURL curl_multi_cleanup(myhandle->curlm); curl_global_cleanup(); @@ -118,6 +114,11 @@ int SYMEXPORT alpm_release(alpm_handle_t *myhandle) #endif
_alpm_handle_unlock(myhandle); + + if(alpm_unregister_all_syncdbs(myhandle) == -1) { + ret = -1; + } + _alpm_handle_free(myhandle);
return ret;
I don't see how this fixes the issue. All you've done is move alpm_unregister_all_syncdbs under _alpm_handle_unlock, but _alpm_handle_unlock doesn't clear the transaction.
If a transaction exists, release it if possible. If `alpm_trans_release` errors out (returns a non-zero), return a -1 in `alpm_release`. This patch addresses the following issue observed in `pyalpm`: https://gitlab.archlinux.org/archlinux/pyalpm/-/issues/25, where `pyalpm` ends up raising twice due to an unexpected failure during handle release, while a transaction is locked. This is a modified version of https://patchwork.archlinux.org/project/pacman/patch/20200119191833.581492-1... and is a derivation of his (Morganamilo's) work. Signed-off-by: Kevin Morris <kevr@0cost.org> --- lib/libalpm/alpm.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 6708e202..47d02fea 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -100,6 +100,10 @@ int SYMEXPORT alpm_release(alpm_handle_t *myhandle) CHECK_HANDLE(myhandle, return -1); + if (myhandle->trans != NULL && alpm_trans_release(myhandle)) { + return -1; + } + /* close local database */ db = myhandle->db_local; if(db) { -- 2.34.0
On 20/11/2021 20:03, Kevin Morris via pacman-dev wrote:
If a transaction exists, release it if possible. If `alpm_trans_release` errors out (returns a non-zero), return a -1 in `alpm_release`.
This patch addresses the following issue observed in `pyalpm`: https://gitlab.archlinux.org/archlinux/pyalpm/-/issues/25, where `pyalpm` ends up raising twice due to an unexpected failure during handle release, while a transaction is locked.
This is a modified version of https://patchwork.archlinux.org/project/pacman/patch/20200119191833.581492-1... and is a derivation of his (Morganamilo's) work.
Signed-off-by: Kevin Morris <kevr@0cost.org> --- lib/libalpm/alpm.c | 4 ++++ 1 file changed, 4 insertions(+)
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c index 6708e202..47d02fea 100644 --- a/lib/libalpm/alpm.c +++ b/lib/libalpm/alpm.c @@ -100,6 +100,10 @@ int SYMEXPORT alpm_release(alpm_handle_t *myhandle)
CHECK_HANDLE(myhandle, return -1);
+ if (myhandle->trans != NULL && alpm_trans_release(myhandle)) { + return -1; + } + /* close local database */ db = myhandle->db_local; if(db) {
So looking through the code, alpm_release calls many functions that may fail but only actually looks at the return value of alpm_unregister_all_syncdbs. alpm_unregister_all_syncdbs can only fail if there's a transaction active, which this patch prevents. We should probably error check all the function calls.
participants (3)
-
Andrew Gregory
-
Kevin Morris
-
Morgan Adamiec