phacility/phabricator · error · Exception
Trying to acquire an active lease on a pending resource. You
Error message
Trying to acquire an active lease on a pending resource. You can not immediately activate leases on resources which need time to start up.
What it means
A lease can request immediate activation (activateWhenAcquired) so that acquisition and activation happen in one step, giving callers a ready-to-use ACTIVE lease. That is only legal if the resource it lands on is already past startup: acquiring-and-activating onto a resource still in STATUS_PENDING would promise an interface that does not exist yet, so acquireOnResource() refuses. Resources that allocate asynchronously (hosts that take time to boot) routinely sit in PENDING, making this a normal outcome of requesting immediate activation.
Source
Thrown at src/applications/drydock/storage/DrydockLease.php:236
$actual_status = $this->getStatus();
if ($actual_status != $expect_status) {
throw new Exception(
pht(
'Trying to acquire a lease on a resource which is in the wrong '.
'state: status must be "%s", actually "%s".',
$expect_status,
$actual_status));
}
if ($this->activateWhenAcquired) {
$new_status = DrydockLeaseStatus::STATUS_ACTIVE;
} else {
$new_status = DrydockLeaseStatus::STATUS_ACQUIRED;
}
if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) {
if ($resource->getStatus() == DrydockResourceStatus::STATUS_PENDING) {
throw new Exception(
pht(
'Trying to acquire an active lease on a pending resource. '.
'You can not immediately activate leases on resources which '.
'need time to start up.'));
}
}
// Before we associate the lease with the resource, we lock the resource
// and reload it to make sure it is still pending or active. If we don't
// do this, the resource may have just been reclaimed. (Once we acquire
// the resource that stops it from being released, so we're nearly safe.)
$resource_phid = $resource->getPHID();
$hash = PhabricatorHash::digestForIndex($resource_phid);
$lock_key = 'drydock.resource:'.$hash;
$lock = PhabricatorGlobalLock::newLock($lock_key);
try {View on GitHub (pinned to 5720a38cfe)
Solutions
- Do not force immediate activation: acquire normally (two-phase), then trigger activation via the lease update worker once the resource becomes ACTIVE
- Have the allocator prefer resources already in STATUS_ACTIVE when the lease demands immediate activation
- If you control resource allocation, set activateWhenAllocated on the resource so it is ACTIVE before leases attach
- Retry land/lease request after the resource activation worker completes — the pending window is transient
Example fix
// before $lease = $blueprint->newLease() ->setActivateWhenAcquired(true) // immediate activation ->queueForActivation(); // allocator picks a pending resource -> Exception // after $lease = $blueprint->newLease() // two-phase: acquire now, activate when resource is ready ->queueForActivation();
Defensive patterns
Strategy: validation
Validate before calling
// Only request immediate activation when the resource is already ACTIVE:
$immediate = ($resource->getStatus() === DrydockResourceStatus::STATUS_ACTIVE);
$lease = $blueprint->newLease();
if ($immediate) {
$lease->setActivateWhenAcquired(true);
}
$lease->queueForActivation(); Try / catch
catch (Exception $ex) { on 'active lease on a pending resource', fall back to two-phase: acquire without immediate activation and let the lease update worker activate once the resource boots } Prevention
- Default to two-phase acquire-then-activate; use activateWhenAcquired only with known-ACTIVE resources
- Prefer blueprints that set activateWhenAllocated on resources when synchronous leases are required
- Design consumers to poll/wait for lease ACTIVation rather than expecting it synchronously
When it happens
Trigger: Creating a lease with setActivateWhenAcquired(true) (or the equivalent force-activation flag) and having the allocator select a freshly-created, still-PENDING resource; racing a resource that is allocated and leased in the same breath before the resource's own activation worker runs.
Common situations: Build systems that want a usable lease synchronously; host blueprints with slow provisioning (Almanac service hosts) where the resource stays PENDING for a while; tests that allocate and lease in one transaction.
Related errors
- Trying to activate a lease on a pending resource.
- Trying to acquire lease ("%s") on a resource ("%s") in the w
- Trying to activate a lease which has the wrong status: statu
- Working copy lease is missing required attribute "%s". Attr
- Use "--lease" to specify a lease.
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/64647d0ac2d09674.
Report an issue: GitHub.