executeAcquire completes the reservation (pod spawn or hot-idle adoption) and activates the worker for the org. On success the returned worker is Hot with this waiter's session already claimed: the session is pre-claimed while the worker is still Reserved, before it ever becomes visible as Hot, so a
(ctx context.Context, claim *sharedWorkerClaim, assignment *WorkerAssignment)
| 242 | p.ReleaseWorker(out.worker.ID) |
| 243 | }() |
| 244 | return orgAcquireOutcome{err: ctx.Err()} |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // executeAcquire completes the reservation (pod spawn or hot-idle adoption) |
| 249 | // and activates the worker for the org. On success the returned worker is Hot |
| 250 | // with this waiter's session already claimed: the session is pre-claimed while |
| 251 | // the worker is still Reserved, before it ever becomes visible as Hot, so a |
| 252 | // concurrently-arriving connection's idle-reuse fast path can never grab the |
| 253 | // worker out from under the waiter that spawned it (the 1:1 waiter↔worker |
| 254 | // binding behind the anti-snatch invariant). |
| 255 | func (p *OrgReservedPool) executeAcquire(ctx context.Context, claim *sharedWorkerClaim, assignment *WorkerAssignment) orgAcquireOutcome { |
| 256 | worker, retry, err := p.shared.completeSharedWorkerReservation(ctx, claim, assignment) |
| 257 | if retry { |
| 258 | return orgAcquireOutcome{retry: true} |
| 259 | } |
| 260 | if err != nil { |
| 261 | return orgAcquireOutcome{err: err} |
| 262 | } |
| 263 | |
| 264 | p.shared.mu.Lock() |
| 265 | worker.claimSessionLocked() |
| 266 | p.shared.mu.Unlock() |
| 267 | |
| 268 | if err := p.activateWorkerForOrg(ctx, worker); err != nil { |
| 269 | slog.Warn("Worker activation failed.", "worker", worker.ID, "org", p.orgID, "error", err) |
| 270 | observeActivationFailure(worker.image) |
| 271 | p.shared.retireWorkerWithReason(worker.ID, RetireReasonActivationFailure, LifecycleOriginActivationFailure) |
| 272 | return orgAcquireOutcome{err: err} |
| 273 | } |
| 274 | |
| 275 | p.shared.mu.Lock() |
| 276 | owned := p.workerBelongsToOrgLocked(worker) |
| 277 | if !owned { |
| 278 | // Worker is no longer ours (raced with retirement/reclaim). Undo the |
| 279 | // pre-claim before re-deciding: if this CP still tracks the worker, a |
| 280 | // stranded activeSessions=1 would make findIdleAssignedWorkerLocked and |
| 281 | // TransitionToHotIdleIfNoSessions skip it forever (fail-safe direction, |
| 282 | // but the worker leaks until a TTL reaper retires it). |
no test coverage detected