diff options
author | melanie witt <melwittt@gmail.com> | 2019-03-20 19:01:33 +0000 |
---|---|---|
committer | melanie witt <melwittt@gmail.com> | 2019-03-27 21:45:52 +0000 |
commit | e4fa061f17353f49615d4850b562699d55a0641b (patch) | |
tree | 54d87bc2d6d43a57163593ad4b8d41353cc587ce /nova/console | |
parent | 926e584136e7dce59f32065292aa4eb8120f628c (diff) | |
download | nova-e4fa061f17353f49615d4850b562699d55a0641b.tar.gz |
Move create of ComputeAPI object in websocketproxy
Currently, we create a compute.rpcapi.ComputeAPI object during
NovaProxyRequestHandler.__init__ in order to make calls to nova-compute
for console token authorizations (port validation). This is problematic
in the event that we receive a TCP RST as it results in constructing a
ComputeAPI object only to throw it away and a large number of TCP RST
sent can cause excessive resource consumption.
This moves the creation of the ComputeAPI object from __init__ to being
lazily instantiated upon first use by access of a property, thus
avoiding creation of ComputeAPI objects when we receive TCP RST
messages.
Closes-Bug: #1816727
Change-Id: I3fe5540ea460fb32767b5e681295fdaf89ce17c5
Diffstat (limited to 'nova/console')
-rw-r--r-- | nova/console/websocketproxy.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/nova/console/websocketproxy.py b/nova/console/websocketproxy.py index 6b69239494..954b9b1ecf 100644 --- a/nova/console/websocketproxy.py +++ b/nova/console/websocketproxy.py @@ -304,12 +304,18 @@ class NovaProxyRequestHandlerBase(object): class NovaProxyRequestHandler(NovaProxyRequestHandlerBase, websockify.ProxyRequestHandler): def __init__(self, *args, **kwargs): - # Order matters here. ProxyRequestHandler.__init__() will eventually - # call new_websocket_client() and we need self.compute_rpcapi set - # before then. - self.compute_rpcapi = compute_rpcapi.ComputeAPI() + self._compute_rpcapi = None websockify.ProxyRequestHandler.__init__(self, *args, **kwargs) + @property + def compute_rpcapi(self): + # Lazy load the rpcapi/ComputeAPI upon first use for this connection. + # This way, if we receive a TCP RST, we will not create a ComputeAPI + # object we won't use. + if not self._compute_rpcapi: + self._compute_rpcapi = compute_rpcapi.ComputeAPI() + return self._compute_rpcapi + def socket(self, *args, **kwargs): return websockify.WebSocketServer.socket(*args, **kwargs) |