Per-lock timeout
The lock key expiration was hardcoded to 30 seconds, which silently capped the critical section: an operation running longer than that lost its lock while still running, and another holder could acquire it concurrently. unlock detected the overrun and skipped the DEL, so the only symptom was an error log and lost mutual exclusion.
The timeout now comes from the caller per lock, since it describes the critical section rather than the client:
try await lock.withLock("a-long-running-job", timeout: .seconds(600)) {
// operations that should be protected by the lock
}Valkey expires keys at whole-second granularity, so the timeout must be at least one second and any sub-second part of it is truncated.
Breaking
- Requires
distributed-lock-swift0.1.0 for the newlock(key:timeout:logger:)andunlock(key:startedAt:timeout:logger:)requirements. - Those two methods changed signature. Anything calling them directly needs the extra argument;
withLockcallers andValkeyLock(client:)are unchanged, and omitting the timeout still gives the 30 seconds this used to hardcode.
Released as 0.1.0 rather than 0.0.4 so from: "0.0.3" consumers do not pick this up without an explicit bump.
Full changelog: 0.0.3...0.1.0