libsql icon indicating copy to clipboard operation
libsql copied to clipboard

Libsql WAL sync pull fails

Open LucioFranco opened this issue 1 year ago • 3 comments

Error

When running the pull example I get this error:

thread 'main' panicked at libsql/examples/offline_writes_pull.rs:41:21:
called `Result::unwrap()` on an `Err` value: SqliteFailure(21, "wal_insert_frame failed")

Reproduction:

  1. create a test namespace that is empty
  2. create a table via the cli create table guest_book_entries (text TEXT);
  3. insert row via cli insert into guest_book_entries (text) values ("foobar");
  4. run the cargo run --example offline_writes_pull and this will produce that error

LucioFranco avatar Dec 05 '24 22:12 LucioFranco

Some further debugging, my debugger seems to skip right after calling xFrameCount and we end up in the rust code right before we return an error. It may be related to the locking though I would need to dig deeper there.

sqlite3PagerWalInsert (pPager=0x555556c75998, iFrame=4120, pBuf=0x7fffbc000d29,
    nBuf=<optimized out>)
    at /home/lucio/code/libsql/libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c:65343
65343     if (!pagerUseWal(pPager)) {
(gdb) s
[Thread 0x7ffff5c736c0 (LWP 60499) exited]
[Thread 0x7ffff5a676c0 (LWP 60508) exited]
65347     rc = pPager->wal->methods.xFrameCount(pPager->wal->pData, 1, &mxFrame);
(gdb) p rc
$15 = 0
(gdb) s

Thread 1 "offline_writes_" hit Breakpoint 3, libsql::local::connection::Connection::wal_insert_frame (self=0x7fffffff4ef0, frame=...) at libsql/src/local/connection.rs:517
517             if rc != 0 {
(gdb) p rc
$16 = 21

LucioFranco avatar Dec 06 '24 22:12 LucioFranco

I am unfortunately not able to reproduce here.

That error code 21 is SQLITE_MISUSE, which suggests validation at the C API level failed, not something that comes from the internals. Furthermore, you see xFrameCount return zero so seems unlikely to be there. Worth digging into more where that 21 comes from exactly.

penberg avatar Dec 11 '24 10:12 penberg

@LucioFranco Nailed down the problem to sqlite3mc. If I enable encryption feature, I can now reproduce:

penberg@vonneumann libsql % cargo run --features encryption --example offline_writes
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.66s
     Running `/Users/penberg/src/tursodatabase/libsql/target/debug/examples/offline_writes`
Syncing database from remote...
thread 'main' panicked at libsql/examples/offline_writes.rs:43:21:
called `Result::unwrap()` on an `Err` value: SqliteFailure(21, "wal_insert_frame failed")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

penberg avatar Dec 12 '24 08:12 penberg