From d685780a4a2db9e6d1f0825ee4b5b1bca2b2ae7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20=C4=8Cerm=C3=A1k?= Date: Thu, 21 Mar 2024 15:58:53 +0100 Subject: [PATCH] Fix IncompleteReadError happening sometimes when reading Systemd logs (#4974) Sometimes an empty line is returned from readuntil when EOF is reached, which seems to be caused by a race of the EOF check in the loop and later check in readuntil. With this fix, I am not able to reproduce the issue anymore. --- supervisor/utils/systemd_journal.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/supervisor/utils/systemd_journal.py b/supervisor/utils/systemd_journal.py index 1ad71bbb0..051222dbd 100644 --- a/supervisor/utils/systemd_journal.py +++ b/supervisor/utils/systemd_journal.py @@ -75,9 +75,11 @@ async def journal_logs_reader( entries: dict[str, str] = {} while not resp.content.at_eof(): line = await resp.content.readuntil(b"\n") - # newline means end of message: - if line == b"\n": - yield formatter_(entries) + # newline means end of message, also empty line is sometimes returned + # at EOF (likely race between at_eof and EOF check in readuntil) + if line == b"\n" or not line: + if entries: + yield formatter_(entries) entries = {} continue