Skip to content

Poll a step no later than its next timeout so timeouts fire on time - #266

Merged
akashdw merged 1 commit into
mainfrom
ad/timeout-aware-poll
Sep 22, 2026
Merged

akashdw merged 1 commit into
mainfrom
ad/timeout-aware-poll

Conversation

@akashdw

@akashdw akashdw commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Pull Request type

  • Bugfix
  • Feature
  • Refactoring (no functional changes, no api changes)
  • Build related changes (Please run ./gradlew build --write-locks to refresh dependencies)
  • Other (please describe):

NOTE: Please remember to run ./gradlew spotlessApply to fix any format violations.

Changes in this PR

A step's timeout is only noticed when the step is polled. For steps in a waiting status, and for step runtimes that ask for their own long poll interval, that poll can be a long way off. Both rely on the wakeup mechanism to react to events, and polling is a safety net in case an event is missed, so the interval is set long on purpose, tens of minutes in some deployments. The timeout check then runs on whichever poll happens to come after the deadline, and we have seen steps time out well after the fact: a step with a 4 hour signal wait and a 30 minute poll times out anywhere up to 4h30.

With this change, when the engine schedules the next poll it looks at the deadlines that apply to the step's current status and never schedules past the earliest one. A step polled a minute before its timeout is polled again at the timeout, not thirty minutes later. The regular interval is untouched for any step whose deadline is further away than the interval, which is every step that does not end up timing out.

This applies equally to the fixed per-status intervals from configuration and to the interval a step runtime requests for itself, so a runtime cannot push a poll beyond a timeout either. Steps that are already past their deadline are polled immediately.

@rdeepak2002 rdeepak2002 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall makes sense to me. I thought about whether there can be any edge cases from weird timeout values but couldn't think of any

Long clockStart = phase.getClockStart(state);
Long limit = limits.get(phase);
if (phase.appliesTo(state.getStatus()) && clockStart != null && limit != null) {
delay = Math.min(delay, Math.max(0, clockStart + limit - now));

@rdeepak2002 rdeepak2002 Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit: limit - (now - clockStart) is safer to prevent overflows, but I guess that shouldn't happen since we have a limit of 120 days

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, switched to limit - (now - clockStart). It also reads the same way as the timeout check right above it.

@akashdw
akashdw force-pushed the ad/timeout-aware-poll branch from c8958b1 to 126a538 Compare September 22, 2026 03:33
@akashdw
akashdw merged commit 1aec679 into main Sep 22, 2026
1 check passed
@akashdw
akashdw deleted the ad/timeout-aware-poll branch September 22, 2026 16:20
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.

2 participants