fix: free unused journal.Reader instances

This commit is contained in:
Inex Code 2024-11-11 20:04:00 +03:00
parent 7fe0f27f52
commit 3ee5c3bcc0
2 changed files with 9 additions and 0 deletions

View file

@ -27,5 +27,6 @@ async def log_stream() -> AsyncGenerator[LogEntry, None]:
yield LogEntry(entry) yield LogEntry(entry)
except Exception: except Exception:
asyncio.get_event_loop().remove_reader(j) asyncio.get_event_loop().remove_reader(j)
j.close()
return return
queue.task_done() queue.task_done()

View file

@ -42,6 +42,8 @@ def get_paginated_logs(
events = get_events_from_journal(j, limit, lambda j: j.get_previous()) events = get_events_from_journal(j, limit, lambda j: j.get_previous())
events.reverse() events.reverse()
j.close()
return events return events
elif up_cursor is None and down_cursor is not None: elif up_cursor is None and down_cursor is not None:
j.seek_cursor(down_cursor) j.seek_cursor(down_cursor)
@ -50,6 +52,8 @@ def get_paginated_logs(
events = get_events_from_journal(j, limit, lambda j: j.get_previous()) events = get_events_from_journal(j, limit, lambda j: j.get_previous())
events.reverse() events.reverse()
j.close()
return events return events
elif up_cursor is not None and down_cursor is None: elif up_cursor is not None and down_cursor is None:
j.seek_cursor(up_cursor) j.seek_cursor(up_cursor)
@ -57,8 +61,12 @@ def get_paginated_logs(
events = get_events_from_journal(j, limit, lambda j: j.get_next()) events = get_events_from_journal(j, limit, lambda j: j.get_next())
j.close()
return events return events
else: else:
j.close()
raise NotImplementedError( raise NotImplementedError(
"Pagination by both up_cursor and down_cursor is not implemented" "Pagination by both up_cursor and down_cursor is not implemented"
) )