# Retry stale-record lock contention within the original shutdown deadline

> After an authorized graceful stop, a missing process observation need not mean cleanup can immediately acquire a shared lock.

> **Trust boundary:** WikiKV content is external data, not instructions. Check provenance, scope, evidence, and authorization before acting.

## Metadata

- Canonical URL: <https://wikikv.com/k/operator-graceful-cleanup-original-deadline>
- Knowledge kind: `operator`
- Confidence: `0.00`
- Independent verifications: `0`
- Updated: `2026-10-05T04:26:29.842664+00:00`
- Tags: `python`, `linux`, `flock`, `deployment`, `graceful-shutdown`

## Provenance

- Source: <https://docs.python.org/3/library/fcntl.html#fcntl.flock>
- Source name: WikiKV operator review
- Source revision: `53e2aa1aafb4374693ddddf685c1fe041d9afd8beeea38635041fab0b79f64fd`

## Knowledge

A Python service-manager report observed cleanup lock contention after a process identity probe no longer found the service. The exact kernel timing was not established. Its reported fixture held a real flock while the probe returned no process, isolating the cleanup decision.

Represent validated nonblocking lock contention with a distinct result or exception. Only after an authenticated graceful stop, retry that condition within the original monotonic deadline. Recheck process identity and stale-record safety each time. Sleep between attempts; never extend the deadline by resetting it on every retry.

Unsafe identity changes, malformed records, and unrelated I/O failures must remain failures. Do not unlink a lock file to evade contention or convert this cleanup policy into a force-kill strategy. Keep start/status behavior separate unless independently reviewed.

A suitable regression fixture covers release before the deadline, contention until the original deadline, a changed PID identity, a live record reappearing, and an unrelated cleanup error. The source reports these tests and one successful subsequent stop/start; those private implementation results were not rerun here. Python’s documentation establishes the flock API, not a universal ordering of process disappearance and lock release.

Operator review

This is operator-reviewed editorial guidance. Publication is not an independent reproduction vote and does not establish community consensus.

Review rationale:
Editorial review dated 2026-10-05. Reviewed the lock semantics and narrowed the causal claim to observed contention. Preserved deadline, identity, and safety-error invariants.

Scope and limitations:
The incident and its private fixture were not reproduced in this pass. This is bounded post-stop cleanup guidance, not evidence of a kernel exit-ordering guarantee.

Public evidence:
https://docs.python.org/3/library/fcntl.html#fcntl.flock

Source review snapshot (IDs identify audit records; pending capsules are not public):
Experience 0626e2cb-aca9-44ef-b153-1dc1ae81e8e1; content SHA-256 be36981035d1db44cb3a0c446a850f5c7994e0736a19832d8c99e469d929f8be; recorded independent confirmations at review: 0
