Skip to content

Add timeout for resource allocation in lock step and freestyle jobs#1010

Merged
github-actions[bot] merged 1 commit intomasterfrom
feature/lock-timeout
Apr 22, 2026
Merged

Add timeout for resource allocation in lock step and freestyle jobs#1010
github-actions[bot] merged 1 commit intomasterfrom
feature/lock-timeout

Conversation

@mPokornyETM
Copy link
Copy Markdown
Contributor

Summary

Adds imeoutForAllocateResource and imeoutUnit parameters to the lock() pipeline step, and lockTimeout/lockTimeoutUnit to freestyle job resource configuration (RequiredResourcesProperty).

When a timeout is set and the resource is not acquired within the specified duration:

  • Pipeline jobs: the build fails with a LockWaitTimeoutException
  • Freestyle jobs: the queue item is cancelled

Implementation

  • LockStep: new imeoutForAllocateResource (long, default 0) and imeoutUnit (String, default MINUTES) fields with @DataBoundSetter
  • LockStepExecution: passes timeout to queueContext(); extended log message shows timeout info
  • QueuedContextStruct: pre-computes imeoutDeadlineMillis at construction; isTimedOut() is a single comparison
  • LockableResourcesManager: single ScheduledFuture targeting the earliest deadline; getNextQueuedContext() removes timed-out entries (same as orphans) and reschedules for the next deadline; LockWaitTimeoutPeriodicWork (15s) as safety-net fallback
  • RequiredResourcesProperty: new lockTimeout/lockTimeoutUnit fields
  • LockableResourcesQueueTaskDispatcher: checkFreestyleTimeout() with pre-computed deadlines per queue item

Testing

  • LockStepTimeoutTest: 5 tests (timeout expires, no timeout waits, timeout succeeds when freed in time, label-based timeout, multiple jobs with different timeouts)
  • FreeStyleTimeoutTest: 3 tests (timeout cancels queue item, no timeout waits, config round-trip)
  • Manual testing confirmed

Documentation

  • lock-with-timeout.md: pipeline scripted/declarative examples, label-based, freestyle usage, timeout values table

Fixes #866
Fixes #849
Fixes #30

@mPokornyETM mPokornyETM requested a review from a team as a code owner April 16, 2026 13:00
@mPokornyETM mPokornyETM force-pushed the feature/lock-timeout branch from 87b8de3 to 0f2b2fe Compare April 17, 2026 08:44
@mPokornyETM mPokornyETM added the merge-in-3-days-without-review Auto-approve countdown label Apr 18, 2026
@github-actions github-actions Bot added merge-in-2-days-without-review Auto-approve countdown and removed merge-in-3-days-without-review Auto-approve countdown labels Apr 19, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Auto-merge countdown: This PR will be auto-approved in 2 day(s) if no review is submitted.

@mPokornyETM mPokornyETM added the ready for review PR is ready for review label Apr 20, 2026
@mPokornyETM mPokornyETM force-pushed the feature/lock-timeout branch 2 times, most recently from 0a4a270 to 7522000 Compare April 20, 2026 08:12
@github-actions
Copy link
Copy Markdown
Contributor

⏸️ Auto-merge countdown PAUSED: CI checks are not passing. The countdown will resume when all checks are green.

@mPokornyETM mPokornyETM force-pushed the feature/lock-timeout branch from 7522000 to 1f79678 Compare April 20, 2026 21:08
@github-actions github-actions Bot added merge-in-1-day-without-review Auto-approve countdown and removed merge-in-2-days-without-review Auto-approve countdown labels Apr 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Auto-merge countdown: This PR will be auto-approved in 1 day(s) if no review is submitted.

Adds timeoutForAllocateResource and timeoutUnit parameters to the lock()
pipeline step and lockTimeout/lockTimeoutUnit to freestyle job resource
configuration. When a timeout is set and the resource is not acquired
within the specified duration, the pipeline build fails with a
LockWaitTimeoutException and the freestyle queue item is cancelled.

Implementation uses a single scheduled task targeting the earliest
deadline across all queued entries, with a periodic safety-net fallback.

Fixes #866
Fixes #849
Fixes #30
@mPokornyETM mPokornyETM force-pushed the feature/lock-timeout branch from 1f79678 to ac136dd Compare April 21, 2026 19:35
@github-actions github-actions Bot removed the merge-in-1-day-without-review Auto-approve countdown label Apr 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Auto-approved: No review received within 3 days. Merging now.

@github-actions github-actions Bot added the merged-without-review Auto-approve countdown label Apr 22, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Auto-approved: no review received within 3 days of opening.

@github-actions github-actions Bot merged commit 475bcfd into master Apr 22, 2026
21 checks passed
@github-actions github-actions Bot deleted the feature/lock-timeout branch April 22, 2026 08:29
MarkEWaite added a commit to jenkinsci/bom that referenced this pull request Apr 24, 2026
jenkinsci/lockable-resources-plugin#1026
notes that the FreeStyleTimeoutTest fails on Jenkins 2.532 and newer.
The test was added in the most recent release (1509.va_6b_5b_5cb_0b_40)
as part of pull request:

* jenkinsci/lockable-resources-plugin#1010

Issue has been reported to the maintainer as:

* jenkinsci/lockable-resources-plugin#1026

Testing done:

* Confirmed that the test passes on Jenkins core versions prior to 2.532
  and fails consistently on 2.532 and later
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation enhancement frontend java Pull requests that update Java code localization merged-without-review Auto-approve countdown ready for review PR is ready for review tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[JENKINS-41699] Add a timeout field [JENKINS-37376] Allow to set the value of the timeout Non-blocking or timeouted lock step

1 participant