diff --git a/nova/console/websocketproxy.py b/nova/console/websocketproxy.py index 6b69239..8b23932 100644 --- a/nova/console/websocketproxy.py +++ b/nova/console/websocketproxy.py @@ -304,15 +304,22 @@ 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) def socket(self, *args, **kwargs): return websockify.WebSocketServer.socket(*args, **kwargs) + def handle_websocket(self): + # ProxyRequestHandler.__init__() will eventually call + # new_websocket_client() and we need self.compute_rpcapi set before + # then. handle_websocket() is called before new_websocket_client(). + # We do this here instead of in __init__() because in the event that + # we receive a TCP RST, we do not want to create a ComputeAPI object, + # and handle_websocket() is not called in the event of a TCP RST. + self.compute_rpcapi = compute_rpcapi.ComputeAPI() + return websockify.ProxyRequestHandler.handle_websocket(self) + class NovaWebSocketProxy(websockify.WebSocketProxy): def __init__(self, *args, **kwargs):