From bf5bf3e560c15ed5a42ca3dfbcda4a8861b61622 Mon Sep 17 00:00:00 2001 From: tsm-odoo Date: Wed, 31 Aug 2022 11:19:51 +0000 Subject: [PATCH] [FIX] bus: websocket cpu usage on keep alive timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this PR, disconnecting the websocket for a keep alive timeout would skip the terminate method. When the loop would exit, gevent loop will keep running and use the CPU up to 100%. This commit ensures the termiante method is called when disconnecting due to a keep alive timeout and solves this issue. closes odoo/odoo#99308 Signed-off-by: Xavier Dollé (xdo) --- addons/bus/websocket.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/bus/websocket.py b/addons/bus/websocket.py index 9d4d6e4da04..950554b43a1 100644 --- a/addons/bus/websocket.py +++ b/addons/bus/websocket.py @@ -273,13 +273,13 @@ class Websocket: selector_key[0].fileobj for selector_key in self._selector.select(type(self).INACTIVITY_TIMEOUT) } - if self._timeout_manager.has_timed_out(): + if self._timeout_manager.has_timed_out() and self.state is ConnectionState.OPEN: self.disconnect( CloseCode.ABNORMAL_CLOSURE if self._timeout_manager.timeout_reason is TimeoutReason.NO_RESPONSE else CloseCode.KEEP_ALIVE_TIMEOUT ) - break + continue if not readables: self._enqueue_ping_frame() continue @@ -415,8 +415,6 @@ class Websocket: self._send_frame(frame) if not isinstance(frame, CloseFrame): return - self.state = ConnectionState.CLOSING - self._close_sent = True if frame.code not in CLEAN_CLOSE_CODES or self._close_received: return self._terminate() # After sending a control frame indicating the connection @@ -504,6 +502,8 @@ class Websocket: def _enqueue_close_frame(self, code, reason=None): """ Put a close frame in the outgoing frame queue. """ + self.state = ConnectionState.CLOSING + self._close_sent = True self._outgoing_frame_queue.put(CloseFrame(code, reason)) def _enqueue_ping_frame(self):