--- title: "ADR 0053: A missing concurrency limit is a semaphore limit of zero" --- * Status: accepted * Code: [`pkg/queue/queue_manager.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/queue/queue_manager.go), [`pkg/queue/semaphore.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/queue/semaphore.go) ## Context `Repository.Spec.ConcurrencyLimit` is a pointer. It can be unset when a queue is first created, or removed later while a semaphore already exists. Something other than Pipelines-as-Code can also set a PipelineRun to Pending. ## Decision * `getSemaphore` and `checkAndUpdateSemaphoreSize` map a nil limit to 0 and do not assume callers checked it; a semaphore with limit 0 means unlimited. * `AddListToRunningQueue` returns every pending run when the limit is nil or 0, and only runs its acquire loop for a positive limit. * `resize` takes only as many slots as the smaller of the running count and the new size. When the limit shrinks, `release` does not free a slot while the running count is still at or above the limit, so the excess drains as runs finish. * `requeue` only releases a semaphore slot when the limit is positive and the running count is below it. ## Consequences * Removing the limit lets all pending runs start at once. * A nil dereference on a removed limit was fixed by the nil check; the test `TestCheckAndUpdateSemaphoreSizeHandlesRemovedLimit` creates the semaphore with a limit first so that path is reached. * A failed `TryAcquire` in `resize` returns an error and leaves the old size in place.