microsoft/FASTER · error · FasterException
Attempting to allocate an already-allocated block
Error message
Attempting to allocate an already-allocated block
What it means
FasterException thrown by the DEBUG-only (CHECK_FREE) guard in BufferPool's SectorAlignedMemory state setter. Each pooled block carries a free/allocated bit; this fires when code calls Allocate() on a block whose kFreeBitMask indicates it is already allocated, i.e. a double-acquire of the same buffer. It indicates broken ownership tracking of pooled sector-aligned memory.
Solutions
- Audit ownership so each SectorAlignedMemory is allocated by exactly one consumer at a time
- Ensure every Allocate is paired with exactly one Free and the reference is not reused after freeing
- Guard shared buffers with synchronization or per-thread pools instead of sharing one pool entry
- Enable/keep CHECK_FREE in tests to catch double allocation before production
Example fix
// before var buf = pool.Get(0); Use(buf); buf.Allocate(); // throws: already allocated // after var buf = pool.Get(0); Use(buf); buf.Free(); var buf2 = pool.Get(0); // allocate a fresh block instead
Defensive patterns
Strategy: validation
Validate before calling
if (buffer.Free) buffer.Allocate(); else throw new InvalidOperationException("Buffer already allocated; fix ownership"); Type guard
bool IsAllocatable(SectorAlignedMemory m) => m != null && m.Free;
Prevention
- Treat pooled buffers as single-owner resources; never share references across consumers
- Pair every Get/Allocate with exactly one Free in a using or try/finally
- Run CHECK_FREE builds in CI to catch double allocation early
When it happens
Trigger: Calling SectorAlignedMemory.Allocate() (via BufferPool.Get/GetBufferPool) on a block that is already marked allocated — typically handing the same SectorAlignedMemory object to two consumers, or calling Allocate twice without a matching Free in between.
Common situations: Refactoring code that returns buffers to the pool while keeping a reference to the old buffer; sharing a buffer across threads without synchronization; custom checkpoint/replay code re-acquiring a saved buffer reference; only surfaces in CHECK_FREE builds so it appears after enabling debug checks.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Attempting to return an already-free block
- Cannot create new SpanByteAndMemory using serialized…
- elementIndex
- Out of order message within session
- Unexpected status of SubscribeKV
AI-assisted analysis of microsoft/FASTER@321d872eab (2026-09-15).
Data as JSON: /api/errors/1bcfc176135e3fe3.
Report an issue: GitHub.
Appendix: source
Thrown at cs/src/core/Utilities/BufferPool.cs:85
internal SectorAlignedBufferPool pool;
#if CHECK_FREE
internal bool Free
{
get => (level & kFreeBitMask) != 0;
set
{
if (value)
{
if (Free)
throw new FasterException("Attempting to return an already-free block");
this.level |= kFreeBitMask;
}
else
{
if (!Free)
throw new FasterException("Attempting to allocate an already-allocated block");
this.level &= ~kFreeBitMask;
}
}
}
#endif // CHECK_FREE
/// <summary>
/// Default constructor
/// </summary>
public SectorAlignedMemory(int level = default)
{
this.level = level;
// Assume ctor is called for allocation and leave Free unset
}
/// <summary>
/// Create new instance of SectorAlignedMemory
/// </summary>View on GitHub (pinned to 321d872eab)