HostLoom.Locking
0.8.0
See the version list below for details.
dotnet add package HostLoom.Locking --version 0.8.0
NuGet\Install-Package HostLoom.Locking -Version 0.8.0
<PackageReference Include="HostLoom.Locking" Version="0.8.0" />
<PackageVersion Include="HostLoom.Locking" Version="0.8.0" />
<PackageReference Include="HostLoom.Locking" />
paket add HostLoom.Locking --version 0.8.0
#r "nuget: HostLoom.Locking, 0.8.0"
#:package HostLoom.Locking@0.8.0
#addin nuget:?package=HostLoom.Locking&version=0.8.0
#tool nuget:?package=HostLoom.Locking&version=0.8.0
HostLoom.Locking
HostLoom.Locking is the backend-neutral distributed lock kernel: the consumer contract
IDistributedLock, the backend contract ILockProvider, the composed DistributedLock that
turns a provider into a lock with leases, retries, owner tokens, and lost-lease detection, and an
in-process provider with the same state machine a distributed backend has. The package references
only Microsoft.Extensions.Logging.Abstractions; every runtime type has a public constructor, so a
lock composes without a container.
The lock is coordination, not correctness. It keeps two instances from doing the same work at the same time. It does not make persisted state correct: a lease can expire while an action is still running, and a provider can lose a lease it granted. Database transactions, row locks, unique constraints, and idempotency records own correctness. Design every action so that running it twice, or running it after the lease was lost, is safe.
var options = new LockingOptions { Namespace = "billing" };
IDistributedLock locks = new DistributedLock(options, new InMemoryLockProvider());
// Acquire, run, release in a finally. Contention past the retry policy throws
// LockNotAcquiredException; a backend failure throws LockProviderUnavailableException.
await locks.ExecuteWithLockAsync(
$"invoice:{invoiceId}",
async token => await SettleAsync(invoiceId, token),
new LockOptions { Lease = TimeSpan.FromSeconds(10), OnLost = LostLeaseBehavior.Cancel },
cancellationToken);
// Skip if busy: one attempt, no wait, null when another owner holds the key.
await using var handle = await locks.TryAcquireAsync("nightly-report", cancellationToken: cancellationToken);
if (handle is not null)
{
await RunReportAsync(handle.LostToken);
}
Keys are opaque strings without whitespace or control characters. The composed lock prefixes them
as {namespace}:lock:{key} before they reach a provider, so consumers never repeat the prefix.
Build a key from a credential with LockKey.FromSensitive, which hashes the value so it never
reaches the provider, a log line, or a span.
Every lease has an owner token generated per acquisition; release and extension succeed only for
the owner. The handle's LostToken is cancelled, IsHeld turns false, and hostloom.lock.lost
increments when the lease expires on the local clock or the provider refuses an extend or a
release. The local clock starts at the request, not at the answer: a provider begins the lease
when it accepts the call, so the round trip is subtracted from the lease the handle reports. With LockOptions.OnLost = LostLeaseBehavior.Cancel the token handed to the action is
cancelled too; the default, Observe, keeps the action running and only reports the loss.
LockRetryPolicy shapes the wait between attempts and never depends on HostLoom.Pipelines. The
default reproduces the platform's historical behaviour: ten retries at a linear 50 ms step with up
to 50 ms of additive jitter, about 3 s in total; LockOptions.MaxWait is a hard wall-clock bound
on top of it, cancelling the provider call it would otherwise outlive, and TimeSpan.Zero makes
exactly one attempt. LockingOptions.Enabled = false is
single-instance mode: a startup warning, hostloom.lock.enabled = 0, and every action running
immediately.
LockingProbe.Describe(lock) reports the composition without executing anything. Metrics and
activities live under the HostLoom.Locking meter and activity source. Install
HostLoom.Locking.DependencyInjection to register the lock with the built-in .NET container.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on HostLoom.Locking:
| Package | Downloads |
|---|---|
|
HostLoom.Locking.DependencyInjection
Microsoft.Extensions.DependencyInjection registration, options validation, and readiness for HostLoom locking. |
|
|
HostLoom.Locking.Testing
Container-free lock composition, scripted, recording, and fault-injecting provider decorators for testing HostLoom locking consumers. |
|
|
HostLoom.Locking.Pipelines
Distributed-lock filter for HostLoom pipelines, built on the HostLoom locking kernel. |
|
|
HostLoom.Leadership
Lease-based leader election for HostLoom over the distributed lock: one elector per role, explicit renewal, a leadership token, and the honest guarantee statement. |
|
|
HostLoom.Scheduling.Locking
Runs exclusive HostLoom schedules on one instance at a time by claiming them through the HostLoom distributed lock. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.17.0 | 26 | 10/25/2026 |
| 0.16.1 | 131 | 10/22/2026 |
| 0.16.0 | 269 | 10/14/2026 |
| 0.15.1 | 194 | 10/12/2026 |
| 0.15.0 | 185 | 10/4/2026 |
| 0.14.0 | 171 | 10/4/2026 |
| 0.13.0 | 190 | 9/28/2026 |
| 0.12.0 | 169 | 9/27/2026 |
| 0.11.0 | 169 | 9/25/2026 |
| 0.10.0 | 178 | 9/22/2026 |
| 0.9.0 | 172 | 9/22/2026 |
| 0.8.0 | 141 | 9/19/2026 |
| 0.7.0 | 140 | 9/17/2026 |
| 0.6.0 | 166 | 9/6/2026 |
| 0.5.0 | 145 | 9/5/2026 |
| 0.4.0 | 148 | 9/3/2026 |