Skip to content

Commit 2c19d29

Browse files
committed
[RD-41463] Do not log full traceback for conn closed warning
- It spams the log too much
1 parent de4206f commit 2c19d29

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

browserdebuggertools/wssessionmanager.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ def _ws_io(self):
9797
# noinspection PyBroadException
9898
try:
9999
yield
100+
except websocket.WebSocketConnectionClosedException as e:
101+
self.exception = e
102+
logging.warning("WS messaging thread terminated due to closed connection")
100103
except Exception as e:
101104
self.exception = e
102105
logging.warning("WS messaging thread terminated with exception", exc_info=True)

tests/unittests/test_wssessionmanager.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,3 +595,32 @@ def test_exceeded_max_failures(self):
595595

596596
self.assertEqual(100, self.session_manager._last_not_ok)
597597
self.assertEqual(4, self.session_manager._message_producer_not_ok_count)
598+
599+
600+
@patch(MODULE_PATH + "logging")
601+
class Test_WSMessageProducer_ws_io(WSMessageProducerTest):
602+
603+
def test_WebSocketConnectionClosedException(self, _logging):
604+
self.ws_message_producer.close = MagicMock()
605+
606+
with self.ws_message_producer._ws_io():
607+
raise WebSocketConnectionClosedException("foo")
608+
609+
_logging.warning.assert_called_once_with(
610+
"WS messaging thread terminated due to closed connection"
611+
)
612+
self.ws_message_producer.close.assert_called_once_with()
613+
614+
def test_other_exception(self, _logging):
615+
self.ws_message_producer.close = MagicMock()
616+
617+
e = Exception("foo")
618+
619+
with self.ws_message_producer._ws_io():
620+
raise e
621+
622+
_logging.warning.assert_called_once_with(
623+
"WS messaging thread terminated with exception", exc_info=True
624+
)
625+
self.ws_message_producer.close.assert_called_once_with()
626+
self.assertEqual(e, self.ws_message_producer.exception)

0 commit comments

Comments
 (0)