Class CommandGate

Namespace: redb.Core.Data
Assembly: redb.Core.dll

Mutual exclusion between the commands and the teardown of ONE physical connection
(tsum garage report, 2026-09-11). A redb connection wrapper is single-command by
design and always carried a fail-fast guard against two concurrent commands - but
teardown was exempt from it, so an HTTP scope's dispose could run under a lazy
loader's in-flight SELECT: NpgsqlOperationInProgressException on Reset, or (timing
depending) an outright hang of scope disposal.
The gate closes both holes and is SHARED by all three providers so the contract
cannot drift:

a command entered after teardown began is refused with
- the lazy loader's cue to fall back to a
detached (fresh-scope) load;
teardown waits for the in-flight command before touching the physical connection;
new entrants bounce the moment the flag is set, so the wait is bounded by one
command.

public sealed class CommandGate

Inheritance

Object→CommandGate

Properties

IsDisposed

Teardown has begun (or completed); new commands are refused.

public bool IsDisposed { get; }

Methods

BudgetFrom(int)

The teardown wait budget derived from the connection's OWN command timeout: a

public static TimeSpan BudgetFrom(int commandTimeoutSeconds)

DisposeAndWaitAsync(TimeSpan)

Marks the gate disposed and WAITS until the in-flight command (if any) releases

public ValueTask DisposeAndWaitAsync(TimeSpan budget)

Enter()

Enters a command. Throws on CONCURRENT use

public CommandGate.Releaser Enter()

Constructors

CommandGate(string, string, string)

A gate whose refusals carry their own explanation - the connection of an ambient transaction is