Skip to main content

with_write_lock

Function with_write_lock 

Source
pub async fn with_write_lock<T, E, F, Fut>(
    session: &PubkySession,
    path: &str,
    operation: F,
) -> Result<T, E>
where E: From<PaykitError>, F: FnOnce(StorageLock) -> Fut, Fut: Future<Output = Result<T, E>>,
Expand description

Run a Pubky read-modify-write operation under an exclusive file lock.

Read the current contents inside operation and use the supplied lock for every mutation. The lock is renewed while the operation runs and released afterward. Transient renewal failures are retried within the last confirmed lease lifetime. Cancellation leaves it to expire. Loss of the lock stops the operation with an uncertain outcome, not a retryable write conflict: a PUT may already have committed. Callers must reconcile before retrying. Contended acquisition is retried with bounded backoff before operation runs. The operation itself is never replayed.

Homeserver 0.16.2 with GCS fences stale publications by object generation. A delayed write may still land before this holder’s first publication; a conflict requires a fresh read, and uncertain shared state needs a confirmed replacement before use. Session creation, capability scope, key rotation, and request timeouts remain the caller’s responsibility.