Ref T2015. This prevents a scenario where 50 lease requests come in, and there are currently no active resources for a blueprint. When this happens, the workers allocate resources and place them into the "ALLOCATING" status, but they then leave the lock (and leave it up to allocateResource to move it to "PENDING").
This means that when the 6th worker gains the lock (for a configuration where the maximum resources is set to 5), it may be looking at a scenario like this:
- Resource 1: ALLOCATING
- Resource 2: ALLOCATING
- Resource 3: ALLOCATING
- Resource 4: ALLOCATING
- Resource 5: ALLOCATING
It can't lease against "ALLOCATING" resources, so it attempts to allocate a new resource, but this fails because the number of resources is at the maximum (and this count does take into account "ALLOCATING" resources).