Ray's Knowledge Base
Unlock

Do not use memory::Arena for a buffer that is created on one thread and freed on another

PitfallVerified 5 Nov 2026Holds project: dftracer-utils
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.

Symptom#

A store Batch was built on one thread and committed on another. The memory leak check reported false leaks.

Cause#

memory::Arena owns a whole pool and keeps its counters per thread. A cross-thread lifetime breaks those counters.

Fix#

Use dstd::StringArena. It owns no pool, so it has no per-thread counters. A small overload was added to copy a key and its value into one contiguous spot. The store write, Batch and SegmentBuilder all use it now.

Evidence#

After the switch, store, index, dstd and coroutine tests passed 141/141. Commit perf(store): write segments from the batch bytes in place.

Also found by searching

  • leak check reports false leaks for a batch committed on another thread
  • memory::Arena used across threads
  • which arena to use for a buffer that moves between threads