[FIX] bus: websocket cpu usage on keep alive timeout

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) <xdo@odoo.com>
This commit is contained in:
tsm-odoo
2022-08-31 14:03:44 +02:00
parent a86d4edb89
commit bf5bf3e560
+4 -4
View File
@@ -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):