Skip to content

fix(polling): treat --timeout as a wall-clock budget, not an attempt count#20

Open
danishashko wants to merge 1 commit into
brightdata:mainfrom
danishashko:fix/timeout-wall-clock
Open

fix(polling): treat --timeout as a wall-clock budget, not an attempt count#20
danishashko wants to merge 1 commit into
brightdata:mainfrom
danishashko:fix/timeout-wall-clock

Conversation

@danishashko

Copy link
Copy Markdown

Problem

poll_until looped exactly timeout_seconds times, sleeping the interval (1s) after each poll but never accounting for the request round-trip. So the stated timeout undercounted real time: --timeout 600 ran 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 --timeout matches 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. tsc clean, full suite passes with no new failures.

…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant