Reload oslo_context after calling monkey_patch()

oslo.context is storing a global thread-local variable which keeps the
request context for the current thread. If oslo.context is imported
before calling monkey_patch(), then this thread-local won't be green and
instead of having one request per green thread, we will have one request
object which will be overwritten every time when a new context is
created.

To workaround the problem, always reload oslo_context.context after
calling monkey_patch() to make sure it uses green thread locals.

Change-Id: Id059e5576c3fc78dd893fde15c963e182f1157f6
Closes-Bug: #1773102
This commit is contained in:
Radoslav Gerganov 2018-08-01 13:54:31 +03:00
parent cc436c2b2a
commit 233ea582f7
1 changed files with 8 additions and 0 deletions

View File

@ -14,6 +14,8 @@
# under the License.
import eventlet
from oslo_utils import importutils
from six.moves import reload_module
from nova import debugger
@ -22,3 +24,9 @@ if debugger.enabled():
eventlet.monkey_patch(os=False, thread=False)
else:
eventlet.monkey_patch(os=False)
# NOTE(rgerganov): oslo.context is storing a global thread-local variable
# which keeps the request context for the current thread. If oslo.context is
# imported before calling monkey_patch(), then this thread-local won't be
# green. To workaround this, reload the module after calling monkey_patch()
reload_module(importutils.import_module('oslo_context.context'))