{"record":{"id":"8c3936f5afdc444c","repo":"phacility/phabricator","slug":"trying-to-activate-lease-with-no-resource","errorCode":null,"errorMessage":"Trying to activate lease with no resource.","messagePattern":"Trying to activate lease with no resource\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/applications/drydock/worker/DrydockLeaseUpdateWorker.php","lineNumber":979,"sourceCode":"          'Blueprint \"%s\" (of type \"%s\") is not properly implemented: it '.\n          'returned from \"%s\" with a lease acquired on the wrong resource.',\n          $blueprint->getBlueprintName(),\n          $blueprint->getClassName(),\n          'acquireLease()'));\n    }\n  }\n\n\n/* -(  Activating Leases  )-------------------------------------------------- */\n\n\n  /**\n   * @task activate\n   */\n  private function activateLease(DrydockLease $lease) {\n    $resource = $lease->getResource();\n    if (!$resource) {\n      throw new Exception(\n        pht('Trying to activate lease with no resource.'));\n    }\n\n    $resource_status = $resource->getStatus();\n\n    if ($resource_status == DrydockResourceStatus::STATUS_PENDING) {\n      throw new PhabricatorWorkerYieldException(15);\n    }\n\n    if ($resource_status != DrydockResourceStatus::STATUS_ACTIVE) {\n      throw new DrydockAcquiredBrokenResourceException(\n        pht(\n          'Trying to activate lease (\"%s\") on a resource (\"%s\") in '.\n          'the wrong status (\"%s\").',\n          $lease->getPHID(),\n          $resource->getPHID(),\n          $resource_status));\n    }","sourceCodeStart":961,"sourceCodeEnd":997,"githubUrl":"https://github.com/phacility/phabricator/blob/5720a38cfe95b00ca4be5016dd0d2f3195f4fa04/src/applications/drydock/worker/DrydockLeaseUpdateWorker.php#L961-L997","documentation":"DrydockLeaseUpdateWorker::activateLease() loads the lease's resource with getResource() and immediately refuses if it is null. A lease in the activation phase must point at a resource row; a null means the lease has no resource PHID set or the referenced resource was deleted. This usually signals data loss or a lease that reached activation without completing acquisition.","triggerScenarios":"The resource was destroyed between acquire and activate and the load now returns null; a lease row whose resourcePHID is empty because acquisition half-completed; manual database edits or a crash between the acquire and the lease update task.","commonSituations":"Aggressive resource reclamation destroying resources under pending leases; race between resource destroy and lease activation workers; restoring a database dump inconsistently.","solutions":["Check the lease's resourcePHID and the existence of that resource before queueing activation work.","If the resource is gone, release or destroy the lease explicitly instead of letting the activation task fail.","Investigate why the lease reached activation without a live resource (look at the lease and resource event logs)."],"exampleFix":"// before\n$lease->waitUntilActive();\n\n// after\n$resource = $lease->getResource();\nif ($resource === null) {\n  $lease->setStatus(DrydockLeaseStatus::STATUS_RELEASED)->save();\n  throw new Exception(pht('Lease \"%s\" lost its resource.', $lease->getPHID()));\n}","handlingStrategy":"validation","validationCode":"if (!$lease->getResourcePHID() || !$lease->getResource()) {\n  // do not queue activation for a lease with no live resource\n  throw new Exception(pht('Lease \"%s\" has no resource.', $lease->getPHID()));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify resourcePHID is set after acquisition before scheduling activation.","Avoid destroying resources that still have active or pending leases."],"tags":["drydock","php","lease","missing-object","data-integrity"],"backgroundTag":"missing-related-object","analyzedSha":"5720a38cfe95b00ca4be5016dd0d2f3195f4fa04","analyzedAt":"2026-08-21T05:07:25.672Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}