From 67daa4b3c21b4030a965cc8dd106adafc418b70e Mon Sep 17 00:00:00 2001 From: Gorka Eguileor Date: Mon, 8 Aug 2022 17:50:53 +0200 Subject: [PATCH] Fix native threads on child process When the parent process used eventlet tpool to run code in native threads then anything the child tries to run in a native thread will hang forever. The reason for that is that the parent has initialize the pool of threads and use a flag to mark that it has been initialized, and when the child is forked then it will have the flag saying that it has been initialized and expects the threads to be running, but they are not. So there is no thread to pick up the job when a greenlet queues the job, so the greenthread waits forever to get the result of the operation. This patch tells eventlet's tpool to clean things up on the child just after forking, that way if the child uses native threads tpool will spawn all the threads again. Closes-Bug: #1983949 Change-Id: If2421427c48faa976d6c6ee9bafe4d563288037b --- oslo_service/service.py | 4 ++++ .../notes/native-threads-on-child-7150690c7caa1013.yaml | 8 ++++++++ 2 files changed, 12 insertions(+) create mode 100644 releasenotes/notes/native-threads-on-child-7150690c7caa1013.yaml diff --git a/oslo_service/service.py b/oslo_service/service.py index fa9c37c2..107a5ddb 100644 --- a/oslo_service/service.py +++ b/oslo_service/service.py @@ -34,6 +34,7 @@ import time import eventlet from eventlet import event +from eventlet import tpool from oslo_concurrency import lockutils from oslo_service._i18n import _ @@ -560,6 +561,9 @@ class ProcessLauncher(object): pid = os.fork() if pid == 0: + # When parent used native threads the library on child needs to be + # "reset", otherwise native threads won't work on the child. + tpool.killall() self.launcher = self._child_process(wrap.service) while True: self._child_process_handle_signal() diff --git a/releasenotes/notes/native-threads-on-child-7150690c7caa1013.yaml b/releasenotes/notes/native-threads-on-child-7150690c7caa1013.yaml new file mode 100644 index 00000000..a6525639 --- /dev/null +++ b/releasenotes/notes/native-threads-on-child-7150690c7caa1013.yaml @@ -0,0 +1,8 @@ +--- +fixes: + - | + `Bug #1983949 + `_: Fixed eventlet + native threads tpool on child process when parent process has used them + before launching the service. +