tursodatabase/turso · critical

buffer not loaded

Error message

buffer not loaded

What it means

Page::as_ptr() (core/storage/pager.rs) hands out a mutable slice of the page buffer and expects buffer to be Some ("buffer not loaded"). Pages whose buffer was taken during eviction or never loaded have buffer=None; touching their contents through get_contents()/as_ptr() panics.

Solutions

  1. Always acquire pages through pager.read_page() / return_if_locked_maybe_load! so the buffer is loaded before contents are touched
  2. Check page.is_loaded() before accessing contents in any custom code
  3. Treat occurrences inside engine paths as bugs - report them with a reproduction
  4. Reduce cache pressure (larger page cache) to avoid eviction windows

Example fix

// before
let contents = page.get_contents(); // panics if evicted: buffer is None
let ptr = contents.as_ptr();

// after
if !page.is_loaded() {
    return Err(LimboError::InternalError(format!("page {} buffer not loaded", page.get().id)));
}
let contents = page.get_contents();
Defensive patterns

Strategy: validation

Validate before calling

// Before touching page contents in custom code over the pager/btree APIs:
if !page.is_loaded() {
    return Err(LimboError::InternalError(format!(
        "page {} buffer not loaded; re-read via pager.read_page()", page.get().id
    )));
}

Type guard

fn is_page_loaded(page: &PageRef) -> bool {
    page.is_loaded()
}

Prevention

When it happens

Trigger: Calling get_contents()/as_ptr() on a PageRef that was not (re)loaded - e.g. a page re-fetched from the cache after eviction without return_if_locked_maybe_load!, or a dirty page whose backing WAL frame was truncated by savepoint rollback.

Common situations: Custom btree/pager code skipping the load macros, heavy cache pressure evicting pages mid-operation, engine regressions in pin/reload discipline. The commit path already carries an explicit unloaded-page guard for this shape.

Related errors


AI-assisted analysis of tursodatabase/turso@8d4a589f8d (2026-08-20). Data as JSON: /api/errors/409a282e90d395e0. Report an issue: GitHub.

Appendix: source

Thrown at core/storage/pager.rs:164

        /// The actual page data buffer. None if not loaded.
        buffer: Option<Arc<Buffer>>,
        /// Start and length of the bytes of `buffer`, kept next to it so a page
        /// read does not go through the `Option`, the `Arc` and the `Buffer`
        /// variant on every access. Null and 0 while `buffer` is `None`.
        data_ptr: *mut u8,
        data_len: usize,
        /// Overflow cells during btree operations
        pub overflow_cells: crate::alloc::Vec<OverflowCell>,
    }

    // SAFETY: data_ptr and data_len only cache the address and length of the
    // bytes owned by `buffer`, an `Arc<Buffer>` that is itself Send and Sync, so
    // PageInner can cross threads exactly as it could before the cache existed.
    unsafe impl Send for PageInner {}
    unsafe impl Sync for PageInner {}

    // Methods moved from PageContent - these provide btree page access
    impl PageInner {
        /// Creates a new PageInner from an Arc<Buffer>.
        pub fn new(buffer: Arc<Buffer>) -> Self {
            let mut inner = Self::unloaded(0);
            inner.set_buffer(buffer);
            inner
        }

        /// Creates a new PageInner with an owned buffer.
        pub fn from_buffer(buffer: Buffer) -> Self {
            Self::new(Arc::new(buffer))
        }

        /// Creates a PageInner with no buffer loaded.
        pub fn unloaded(id: usize) -> Self {
            Self {
                flags: AtomicUsize::new(0),
                id,
                header_offset: Self::header_offset_of(id),

View on GitHub (pinned to 8d4a589f8d)