diff --git a/astrbot/_internal/protocols/lsp/client.py b/astrbot/_internal/protocols/lsp/client.py index a600fb901..049d2db9e 100644 --- a/astrbot/_internal/protocols/lsp/client.py +++ b/astrbot/_internal/protocols/lsp/client.py @@ -55,8 +55,8 @@ class AstrbotLspClient(BaseAstrbotLspClient): await reader_task except asyncio.CancelledError: pass - except Exception: - pass + except Exception as exc: + log.debug("Ignoring failed LSP reader task during teardown", exc_info=exc) def _handle_reader_task_done(self, task: asyncio.Task[None]) -> None: if self._reader_task is task: diff --git a/tests/unit/test_internal/test_lsp_client.py b/tests/unit/test_internal/test_lsp_client.py index 48299a7f5..d7b6a0af4 100644 --- a/tests/unit/test_internal/test_lsp_client.py +++ b/tests/unit/test_internal/test_lsp_client.py @@ -30,8 +30,15 @@ async def test_lsp_reader_task_failure_marks_client_disconnected_and_logs(): patch("astrbot._internal.protocols.lsp.client.log") as mock_log, ): await client.connect_to_server(["python", "fake_lsp.py"], "file:///tmp") - await asyncio.sleep(0) - await asyncio.sleep(0) + + for _ in range(100): + if client.connected is False and mock_log.error.called: + break + await asyncio.sleep(0.01) + else: + pytest.fail( + "Timed out waiting for LSP reader task failure to disconnect client and log error" + ) assert client.connected is False mock_log.error.assert_called_once()