Batch timer: make it interruptable by termination flag#635
Merged
assaf758 merged 1 commit intomlrun:developmentfrom Mar 24, 2026
Merged
Batch timer: make it interruptable by termination flag#635assaf758 merged 1 commit intomlrun:developmentfrom
assaf758 merged 1 commit intomlrun:developmentfrom
Conversation
alxtkr77
approved these changes
Mar 24, 2026
gtopper
approved these changes
Mar 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue: test_batch_by_user_key "hangs"
Root cause: Commit c34fda6 replaced cancel() on the timer task with a _terminating flag + await self._timeout_task. The problem: _sleep_and_emit calls asyncio.sleep(flush_after_seconds) which doesn't observe the _terminating flag mid-sleep. Since the test uses flush_after_seconds=100, termination would block for up to 100 seconds waiting for the sleep to finish.
Fix: Replace asyncio.sleep(remaining) with asyncio.wait_for(self._stop_timer_event.wait(), timeout=remaining)
An asyncio.Event (_stop_timer_event) is created when the timer task starts and set immediately when _terminating is flagged. This wakes the sleeping timer instantly while still allowing any in-progress _emit_batch call to complete cleanly (the cancel-safety concern from c34fda6 is preserved).