Skip to content

Commit f56c8f8

Browse files
committed
LogPusher: drop redundant close check; outer loop handles it
Replace ``while True`` + mid-loop close returns with ``while not self._closed``. The close check after rebuffer is gone; the backoff wait still breaks on close via ``_closed``, and the outer loop then exits naturally at the next iteration. Semantics unchanged — one best-effort drain pass on close, then exit.
1 parent 6daf1c6 commit f56c8f8

1 file changed

Lines changed: 11 additions & 12 deletions

File tree

lib/iris/src/iris/log_server/client.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,13 +179,18 @@ def _rebuffer_at_head_locked(self, items: list[tuple[str, logging_pb2.LogEntry]]
179179
# ------------------------------------------------------------------
180180

181181
def _run(self) -> None:
182-
"""Drain loop: wait for buffered entries, send them, retry failures with backoff."""
183-
while True:
182+
"""Drain loop: wait for buffered entries, send them, retry failures with backoff.
183+
184+
Close semantics: on ``close()`` the drain thread performs exactly
185+
one best-effort send pass over whatever is buffered, then exits.
186+
A second attempt against a presumably-dead server on close would
187+
just delay shutdown by the RPC timeout.
188+
"""
189+
while not self._closed:
184190
with self._cond:
185191
while not self._closed and not self._queue:
186192
self._cond.wait(timeout=self._flush_interval)
187193
if not self._queue:
188-
# _closed must be True here; nothing left to flush.
189194
return
190195
items = self._take_queue_locked()
191196

@@ -196,17 +201,11 @@ def _run(self) -> None:
196201

197202
with self._cond:
198203
self._rebuffer_at_head_locked(unsent)
199-
if self._closed:
200-
# Best-effort on close: don't loop forever against an
201-
# unreachable server. Unsent entries are left in the
202-
# queue and lost on process exit.
203-
return
204204
# Sleep on the backoff clock. Push-triggered notifies would
205205
# re-wake us immediately and defeat the backoff, so we loop
206-
# on _cond.wait until the deadline passes — only ``close()``
207-
# can (correctly) shortcut by setting ``_closed``. If close
208-
# wins the race, the next iteration of the outer loop sees
209-
# ``_closed`` and returns.
206+
# on _cond.wait until the deadline passes. ``close()`` breaks
207+
# the wait via ``_closed``; the outer ``while not self._closed``
208+
# then terminates the drain loop.
210209
deadline = time.monotonic() + self._backoff.next_interval()
211210
with self._cond:
212211
while not self._closed:

0 commit comments

Comments
 (0)