TECHNOLOGY

Stop publishing when an etcd lock session ends

In this article
THE QUICK TAKE

Session completion is a loss-of-authority signal, not proof that a computation stopped or an external write was undone; guard publication and reconcile in-flight work.

Computation can outlive its authority

A worker holds a distributed lock while producing a checkpoint manifest. Its connection fails, the lock session ceases refreshing and another worker may eventually acquire the resource. The original computation can continue using CPU or accelerator resources unless the application stops it. A successful lock acquisition at startup does not authorize publication indefinitely. The operational question is how the worker responds when the lifetime that supported ownership ends, including a write that may already have crossed into an external service.

Interpret the client signal precisely

The etcd concurrency client v3.6.0 documents Session.Done as closing when the lease is orphaned, expires or is otherwise no longer refreshed. That is a reason to stop relying on the session, not a precise observation of the server’s expiry instant. Orphan ends refresh, while cancellation before Close finishes can leave the lease to expire instead of proving successful revocation. The Lock reference separately defines the lease-bound ownership key. Preserve those distinct observations when diagnosing why a worker lost authority or why a successor has not yet acquired it.

Connect cancellation to the protected work

A context used to acquire a mutex is not automatically the application’s cancellation mechanism for all computation performed afterward. Define a worker lifecycle that observes session completion, prevents new protected operations and requests cancellation of the actual computation. If a GPU kernel or external operation cannot stop immediately, withhold publication until ownership is valid under the chosen protocol. For updates inside etcd, use the documented ownership condition in the same transaction as the mutation. A separate ownership check followed by an unconditional external write still leaves a race.

Reconcile what was already dispatched

Maintain a record of the output candidate and any external operation sent before session loss. A command not yet dispatched differs from a write accepted by the destination whose acknowledgement was lost. The API guarantees explicitly recognize uncertain outcomes after timeout or transport disruption. Do not turn a local cancellation signal into a claim that all previous writes were reversed. Operation and attempt identity provides the separate retry contract needed to reconcile an already accepted effect before another worker repeats the same business action.

Reacquire under a fresh ownership decision

Creating a replacement session does not automatically restore the former lock or make old output eligible for publication. Acquire the intended lock, identify the current resource revision and inspect whether another worker completed the task in the meantime. Reuse a candidate only if its inputs and acceptance criteria still match. Otherwise preserve it as an obsolete attempt rather than overwriting the successor’s work. Record the new session and ownership generation separately from the logical job so recovery does not erase the history explaining a duplicate or conflicting result.

Test the loss path, not only successful locking

In an isolated fixture, interrupt lease refresh while a worker is computing and delay its destination response. Verify that session completion blocks new publication, triggers the intended cancellation path and leaves uncertain effects explicitly unresolved until checked. Then allow reacquisition and confirm that accepted successor work remains intact. Local lock lifetime and Shared lock-manager scope describe related but different boundaries. Acceptance means the worker stops acting on expired authority and resumes through a new checked decision; it does not require pretending every running operation can be canceled instantly or that lease renewal is a transaction across arbitrary external systems.

Earn rental income from GPUs

Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.

Explore GPU hosting
← All articles