Skip to content

Commit

Permalink
Don't use singleton in routes.middleware.RoutesMiddleware
Browse files Browse the repository at this point in the history
It seems that using default singleton=True in the
routes.middleware.RoutesMiddleware which is leading to use thread-local
RequestConfig singleton object is not working well with eventlet
monkeypatching of threading library which we are doing in Neutron.
As a result it leaks memory in neutron-api workers every time when API
request to not existing API endpoint is made by user.

To avoid that memory leak, let's use singletone=False in that
RoutesMiddleware object, at least until problem with thread-local
singleton and eventlet monkey patching will be solved.

Closes-Bug: #1942179
Change-Id: Id3a529248d3984506f0166bdc32e334127a01b7b
  • Loading branch information
slawqo committed Sep 4, 2021
1 parent c235232 commit e610a5e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion neutron/api/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,13 @@ def __init__(self, application,
controller = req_controllers[request_ext.key]
controller.add_handler(request_ext.handler)

# NOTE(slaweq): It seems that using singleton=True in conjunction
# with eventlet monkey patching of the threading library doesn't work
# well and there is memory leak. See
# https://bugs.launchpad.net/neutron/+bug/1942179 for details
self._router = routes.middleware.RoutesMiddleware(self._dispatch,
mapper)
mapper,
singleton=False)
super(ExtensionMiddleware, self).__init__(application)

@classmethod
Expand Down

0 comments on commit e610a5e

Please sign in to comment.