Comment 5 for bug 1942179

Revision history for this message
Rodolfo Alonso (rodolfo-alonso-hernandez) wrote : Re: neutron api worker leaks memory when processing requests to not existing controllers

Hello:

Slawek found the place where Neutron was leaking memory. This is in the "routes.middleware.RoutesMiddleware" object. When using "singleton=True" (default value), a routes._RequestConfig() is always created [1]. This object has a thread safe variable to store the context information for each request.

The problem is that we use evenlet and we monkey patch the "threading" module (among many other ones) at the beginning of the Neutron server. The equivalent to "threading.local()" [1] is "eventlet.corolocal.local()". This object stores the greenthread-safe parameters in a WeakKeyDictionary() located in "eventlet.corolocal.local()._local__greens".

The problem we see is that this dictionary is not released. The patch provided in the next comment fixes this issue (this is just for testing, this patch could not land "routes" repository).

However, I think this is over engineering. The patch proposed by Slawek, using "singleton-=False" is a valid solution when using greenthreads.

Regards.

[1]https://github.com/bbangert/routes/blob/c4d5a5fb693ce8dc7cf5dbc591861acfc49d5c23/routes/middleware.py#L98
[2]https://github.com/bbangert/routes/blob/c4d5a5fb693ce8dc7cf5dbc591861acfc49d5c23/routes/__init__.py#L12