You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
POST /workloads: concurrent create of one new name can hand the owner to the later writer #356
POST /workloads is check-then-act (packages/knative-server/src/server.ts, handleCreateWorkload):
findWorkload(name) checks for a live workload that another subject owns, and answers 409 workload_name_taken if there is one.
createWorkload() calls Context Service.
saveWorkload() writes the record with owner = <caller subject>.
Nothing makes steps 1–3 atomic. When two subjects create the same new name at the same moment, both pass step 1. If Context Service's create is idempotent for an existing pool name (not verified), both get 201, and the later saveWorkload sets the owner. The subject that lost now holds a 201 for a workload that answers it 404, while the other subject owns a pool the first one may already have started using.
A lost sh:workload:<id> record has the same effect (compose and deploy/vm Redis have no volume): if Context Service's create is idempotent, the next caller to create that name takes over the live pool.
Proposed fix
Before calling Context Service, reserve the owner with a set-if-absent write (SET NX, with a TTL so a crashed create cannot hold the name for ever). Release or confirm the reservation after saveWorkload. RedisResultStore only has get/set today, so this needs setIfAbsent and delete. The handling must also cover a record whose status is deleted: a name must be reusable once its workload is deleted.
Tests: two concurrent creates of one name by different subjects give exactly one 201, and the stored owner matches it.
Context
Found in the self-review of #350 (MI1 S1). It is recorded as deferred in docs/specs/2026-09-28-moca-multi-user-isolation-design.md §13 ("An atomic workload create"), and the code comment in handleCreateWorkload points there. #350's ownership checks (ownedBy, mayDelete, the 409) are otherwise pinned by packages/knative-server/test/workload-auth-route.test.ts.
Round 3 of #350's review found that the create race is only half of it. handleGetWorkload's ownership check and its saveWorkload are also a Context Service round trip apart, so GET is a writer too. Alice's in-flight GET can land after she deletes the workload and Bob re-creates it, and overwrite his record with owner=alice, or bring back a record just marked deleted. A set-if-absent at create does not cover that; it needs a compare-and-set against the record read at the check, or GET not writing ownership fields. The full description is in #363. Fix both together.
Closing: the code this issue was filed against no longer exists, and the rewrite that replaced it removes every leg of the race.
handleCreateWorkload in server.ts (check-then-act: findWorkload → Context Service → saveWorkload) was replaced by the workload lifecycle in packages/knative-server/src/workloads.ts:
Atomic create. The RESERVE Lua script checks the name and quota and writes the reservation in one atomic Redis operation. A same-name create racing an in-flight one answers 409 workload_name_taken — pinned by the first lifecycle races test in packages/knative-server/test/workloads.test.ts (4a6a57d).
Cross-subject name contention no longer exists. Record keys are subject-scoped (sh:wl:<sha256(owner)>:<name>, the first half of /workloads: authorize caller-named PVCs per subject, and scope workload names #358), and contextName derives from owner + name + generation. Two subjects creating the same name each get their own record and Context, so the issue's proposed acceptance test ("two concurrent creates by different subjects give exactly one 201") no longer applies — both 201s are the specified behavior now.
A lost record can't hand over a live pool. A missing record only frees the name for its owner; a fresh create derives a new contextName (new generation) and can never take over a live Context.
A crashed create cannot hold the name forever. A record stuck in creating keeps the name and its quota unit, but the owner's DELETE cleans it up from every live status, and generation-CAS keeps a stale create from rolling back a newer Context — both pinned by the other lifecycle races tests. No reservation TTL is needed.
Deleted names are reusable — RESERVE only refuses records whose status is not deleted.
The MI1 spec's §13 row carries the closure note. The only commit is the pin test; no production change was needed.
Activity
docs: link MI1 S1's deferred gaps to their tracking issues
pdettori commentedon Sep 29, 2026
Round 3 of #350's review found that the create race is only half of it.
handleGetWorkload's ownership check and itssaveWorkloadare also a Context Service round trip apart, so GET is a writer too. Alice's in-flight GET can land after she deletes the workload and Bob re-creates it, and overwrite his record withowner=alice, or bring back a record just markeddeleted. A set-if-absent at create does not cover that; it needs a compare-and-set against the record read at the check, or GET not writing ownership fields. The full description is in #363. Fix both together.Assisted-By: Claude (Anthropic AI) [email protected]
pdettori commentedon Oct 16, 2026
Closing: the code this issue was filed against no longer exists, and the rewrite that replaced it removes every leg of the race.
handleCreateWorkloadinserver.ts(check-then-act:findWorkload→ Context Service →saveWorkload) was replaced by the workload lifecycle inpackages/knative-server/src/workloads.ts:RESERVELua script checks the name and quota and writes the reservation in one atomic Redis operation. A same-name create racing an in-flight one answers409 workload_name_taken— pinned by the firstlifecycle racestest inpackages/knative-server/test/workloads.test.ts(4a6a57d).sh:wl:<sha256(owner)>:<name>, the first half of /workloads: authorize caller-named PVCs per subject, and scope workload names #358), andcontextNamederives from owner + name + generation. Two subjects creating the same name each get their own record and Context, so the issue's proposed acceptance test ("two concurrent creates by different subjects give exactly one201") no longer applies — both201s are the specified behavior now.contextName(new generation) and can never take over a live Context.handleWorkloadsreads the record and answerspublicView; it never writes ownership fields. (The comment above asked to fix both together; the second half needed no code because the writer went away.)creatingkeeps the name and its quota unit, but the owner's DELETE cleans it up from every live status, and generation-CAS keeps a stale create from rolling back a newer Context — both pinned by the otherlifecycle racestests. No reservation TTL is needed.RESERVEonly refuses records whose status is notdeleted.The MI1 spec's §13 row carries the closure note. The only commit is the pin test; no production change was needed.
Assisted-By: Claude (Anthropic AI) [email protected]