jenkinsci / jenkinsci/lockable-resources-plugin

Locking by label from 2 jobs exact the same time causes lock up of one of them

Open
#123 4 comments 7 reactions 0 assignees View on GitHub
parallelism and races resource conflicts or cleanup handled poorly Triage
Dominant language
Java
Stars
99
Forks
205
Avg merge
2d 13h
Merged PRs (30d)
8

Description

The Situation:
- We have 2 pipeline jobs starting the exact same time running on 2 different agents.
- We have 3 registered lockable resources with the same label.

This is what happens:
- Both jobs reach the lock command for a label exact the same time
- Both jobs get the same resource back and try to lock it
- Only one job continues with the locked resource, the other one waits.

What should have happened:
- Both jobs reach the lock command for a label exact the same time
- Each job gets another resource name back and locks it
- Both jobs continue each with their locked resource

Shared pipeline code for both jobs:

```
lock(label: 'STP-' + CFG_NR, variable: 'STPCLONE') {
echo "Current Lock on Clones: " + env.STPCLONE
.... Lot more code ....
}
```

Our Lockable Resource configuration:
(Manually entered in Jenkins configuration!)

```
Name: STP-S2D01
Labels: STP-001
```

```
Name: STP-S4D04
Labels: STP-001
```

```
Name: STP-S1D04
Labels: STP-001
```

Job 1 Console

```
[Pipeline] lock
22:43:19 Trying to acquire lock on [Label: STP-001, Quantity: 1]
22:43:19 Lock acquired on [Label: STP-001, Quantity: 1]
[Pipeline] {
[Pipeline] echo
22:43:19 Current Lock on Clone: STP-S2D01
```

Job 2 Console

```
[Pipeline] lock
22:43:19 Trying to acquire lock on [Label: STP-001, Quantity: 1]
22:43:20 [Label: STP-001, Quantity: 1] is locked, waiting...
06:40:13 Lock acquired on [Label: STP-001, Quantity: 1]
[Pipeline] {
[Pipeline] echo
06:40:13 Current Lock on Clone: STP-S2D01
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with two pipeline jobs calling lock(label: 'STP-' + CFG_NR, variable: 'STPCLONE') against the three STP-001 resources, then compare both console logs. Investigate the label-based allocation and locking path responsible for returning STP-S2D01 to both jobs. Done means simultaneous jobs acquire different resources and both continue without waiting.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
ci-cd
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.