|
Panu Matilainen |
9a8f20 |
From 531dc8495cd3aabd3f659ecab604106fdbacbe98 Mon Sep 17 00:00:00 2001
|
|
Panu Matilainen |
9a8f20 |
Message-Id: <531dc8495cd3aabd3f659ecab604106fdbacbe98.1539244476.git.pmatilai@redhat.com>
|
|
Panu Matilainen |
9a8f20 |
From: Panu Matilainen <pmatilai@redhat.com>
|
|
Panu Matilainen |
9a8f20 |
Date: Wed, 3 Oct 2018 11:51:38 +0300
|
|
Panu Matilainen |
9a8f20 |
Subject: [PATCH] Fix ancient python GIL locking bug on callback
|
|
Panu Matilainen |
9a8f20 |
(RhBug:1632488)
|
|
Panu Matilainen |
9a8f20 |
|
|
Panu Matilainen |
9a8f20 |
Introduced in commit c7881d801745b4c156a8aa2afc17b95f97481e34 back in 2002,
|
|
Panu Matilainen |
9a8f20 |
synthesizing a python object for the callback occurs before retaking
|
|
Panu Matilainen |
9a8f20 |
the GIL lock, which is not allowed. Somehow this has managed to stay
|
|
Panu Matilainen |
9a8f20 |
latent all these years, and even now requires fairly specific conditions:
|
|
Panu Matilainen |
9a8f20 |
when the callback gets called without an associated key, such as erasures
|
|
Panu Matilainen |
9a8f20 |
or file trigger script start/stop events (in the case of RhBug:1632488),
|
|
Panu Matilainen |
9a8f20 |
when Python 3 is running in PYTHONMALLOC=debug mode,
|
|
Panu Matilainen |
9a8f20 |
it crashes with "Python memory allocator called without holding the GIL".
|
|
Panu Matilainen |
9a8f20 |
|
|
Panu Matilainen |
9a8f20 |
Simply retake the lock before any Python operations take place to fix.
|
|
Panu Matilainen |
9a8f20 |
---
|
|
Panu Matilainen |
9a8f20 |
python/rpmts-py.c | 4 ++--
|
|
Panu Matilainen |
9a8f20 |
1 file changed, 2 insertions(+), 2 deletions(-)
|
|
Panu Matilainen |
9a8f20 |
|
|
Panu Matilainen |
9a8f20 |
diff --git a/python/rpmts-py.c b/python/rpmts-py.c
|
|
Panu Matilainen |
9a8f20 |
index e4c5e1250..1ddfc9a1e 100644
|
|
Panu Matilainen |
9a8f20 |
--- a/python/rpmts-py.c
|
|
Panu Matilainen |
9a8f20 |
+++ b/python/rpmts-py.c
|
|
Panu Matilainen |
9a8f20 |
@@ -495,6 +495,8 @@ rpmtsCallback(const void * hd, const rpmCallbackType what,
|
|
Panu Matilainen |
9a8f20 |
|
|
Panu Matilainen |
9a8f20 |
if (cbInfo->cb == Py_None) return NULL;
|
|
Panu Matilainen |
9a8f20 |
|
|
Panu Matilainen |
9a8f20 |
+ PyEval_RestoreThread(cbInfo->_save);
|
|
Panu Matilainen |
9a8f20 |
+
|
|
Panu Matilainen |
9a8f20 |
/* Synthesize a python object for callback (if necessary). */
|
|
Panu Matilainen |
9a8f20 |
if (pkgObj == NULL) {
|
|
Panu Matilainen |
9a8f20 |
if (h) {
|
|
Panu Matilainen |
9a8f20 |
@@ -506,8 +508,6 @@ rpmtsCallback(const void * hd, const rpmCallbackType what,
|
|
Panu Matilainen |
9a8f20 |
} else
|
|
Panu Matilainen |
9a8f20 |
Py_INCREF(pkgObj);
|
|
Panu Matilainen |
9a8f20 |
|
|
Panu Matilainen |
9a8f20 |
- PyEval_RestoreThread(cbInfo->_save);
|
|
Panu Matilainen |
9a8f20 |
-
|
|
Panu Matilainen |
9a8f20 |
args = Py_BuildValue("(iLLOO)", what, amount, total, pkgObj, cbInfo->data);
|
|
Panu Matilainen |
9a8f20 |
result = PyEval_CallObject(cbInfo->cb, args);
|
|
Panu Matilainen |
9a8f20 |
Py_DECREF(args);
|
|
Panu Matilainen |
9a8f20 |
--
|
|
Panu Matilainen |
9a8f20 |
2.17.1
|
|
Panu Matilainen |
9a8f20 |
|