From aacf433edaca043c5164eaa5c45556c140b8b36a Mon Sep 17 00:00:00 2001 From: Rodolfo Alonso Hernandez Date: Thu, 2 Apr 2020 13:49:19 +0000 Subject: [PATCH] Replace ctype.CDLL by ctypes.PyDLL in linux.ip_lib Some linux.ip_lib functions make use of "ctype.CDLL" methods (create_netns, remove_netns). Those methods are called inside a "privsep" context; that means the function reference and the arguments are passed to a privileged context that will execute the method. "privsep" library makes use of eventlet to implement multitasking. If the method executed returns the GIL, nothing guarantees that the "eventlet" executor will return it again to this task. This could lead to timeouts during the execution of those methods. From https://docs.python.org/3.6/library/ctypes.html#ctypes.PyDLL: "Instances of this class behave like CDLL instances, except that the Python GIL is not released during the function call, and after the function execution the Python error flag is checked." Change-Id: I36ef9bf59e9c93f50464457a5d9a968738844079 Closes-Bug: #1870352 (cherry picked from commit 306280813f34f8bbe384ae5bea67f0f66e316b61) --- neutron/privileged/agent/linux/ip_lib.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/neutron/privileged/agent/linux/ip_lib.py b/neutron/privileged/agent/linux/ip_lib.py index ff642cea2f1..0580cfe68d2 100644 --- a/neutron/privileged/agent/linux/ip_lib.py +++ b/neutron/privileged/agent/linux/ip_lib.py @@ -34,7 +34,13 @@ _CDLL = None def _get_cdll(): global _CDLL if not _CDLL: - _CDLL = ctypes.CDLL(ctypes_util.find_library('c'), use_errno=True) + # NOTE(ralonsoh): from https://docs.python.org/3.6/library/ + # ctypes.html#ctypes.PyDLL: "Instances of this class behave like CDLL + # instances, except that the Python GIL is not released during the + # function call, and after the function execution the Python error + # flag is checked." + # Check https://bugs.launchpad.net/neutron/+bug/1870352 + _CDLL = ctypes.PyDLL(ctypes_util.find_library('c'), use_errno=True) return _CDLL