fix: refine lsp reader failure handling

This commit is contained in:
邹永赫
2026-03-26 03:05:26 +09:00
parent a05fab371a
commit 466105d38a
2 changed files with 11 additions and 4 deletions

View File

@@ -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:

View File

@@ -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()