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
This commit is contained in:
Gorka Eguileor 2022-08-08 17:50:53 +02:00
parent a27acfe23f
commit 67daa4b3c2
2 changed files with 12 additions and 0 deletions

View File

@ -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()

View File

@ -0,0 +1,8 @@
---
fixes:
- |
`Bug #1983949
<https://bugs.launchpad.net/oslo.service/+bug/1983949>`_: Fixed eventlet
native threads tpool on child process when parent process has used them
before launching the service.