diff --git a/src/db.zig b/src/db.zig index d197603..0f80a43 100644 --- a/src/db.zig +++ b/src/db.zig @@ -1670,6 +1670,14 @@ pub const Engine = struct { var coll_it = colls.iterator(); while (coll_it.next()) |ce| { const coll = ce.value_ptr.*; + // Everything below this line is written by a collection's own + // writer under its own lock, and `slab_extents` is an ArrayList + // that `slab_reserve` appends to -- so reading it under only the + // shared catalog lock could walk a slice a concurrent append had + // already reallocated. Lock order is catalog then collection, + // the same order `compact` uses. + try coll.lock.lockShared(self.io); + defer coll.lock.unlockShared(self.io); try put_bytes(gpa, out, ce.key_ptr.*); try put_u64(gpa, out, coll.slab_tail); try put_u64(gpa, out, coll.slab_end);