Skip to content

Commit

Permalink
Fix IncompleteReadError happening sometimes when reading Systemd logs (
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
sairon authored Mar 21, 2024
1 parent b6bc8b7 commit d685780
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions supervisor/utils/systemd_journal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d685780

Please sign in to comment.