fix(polling): treat --timeout as a wall-clock budget, not an attempt count#20
Open
danishashko wants to merge 1 commit into
Open
fix(polling): treat --timeout as a wall-clock budget, not an attempt count#20danishashko wants to merge 1 commit into
danishashko wants to merge 1 commit into
Conversation
…count poll_until looped exactly timeout_seconds times, sleeping the interval after each request but never accounting for the request round-trip. So --timeout 600 ran for roughly 12 min instead of 10: every poll's fetch time stacked on top of the 1s interval. Poll until a real wall-clock deadline (timeout_seconds * 1000) instead, so the stated timeout matches real elapsed time. Updates the timeout test to fake timers so it stays fast.
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.
Problem
poll_untillooped exactlytimeout_secondstimes, sleeping the interval (1s) after each poll but never accounting for the request round-trip. So the stated timeout undercounted real time:--timeout 600ran for roughly 12 minutes instead of 10, because each of the 600 polls added its own fetch time on top of the 1s sleep. This is the "create timed out / failed, but the collector was fine minutes later" surprise.Fix
Poll until a real wall-clock deadline (
Date.now() + timeout_seconds * 1000) instead of counting iterations, and stop before a sleep that would run past the budget. Now the stated--timeoutmatches real elapsed time regardless of how slow each request is.Tests
Updated the timeout test to fake timers (
vi.useFakeTimers+advanceTimersByTimeAsync) so it verifies the wall-clock behaviour without waiting in real time.tscclean, full suite passes with no new failures.