SQLite Forum


5 forum posts by user jhemphill

16:01 Reply: Database disk image is malformed (artifact: 6cbbc07f16 user: jhemphill)

I encountered a similar problem in HHVM.

The root cause of the corruption was that unrelated code in HHVM was sometimes writing to a closed file descriptor. When you write to a closed file descriptor, you’re playing Russian Roulette with the files you currently have open, and there’s a chance you’ll write unspecified data to an unspecified place in your SQLite DB, instead of writing to the file you wanted to write to.

I was able to debug this issue by writing a C program that ran PRAGMA integrity_check on my DB. I then compiled it with all optimizations off, and stepped through it with GDB. GDB showed me that an int had a value of 115, which was impossible if only SQLite were writing to the DB file. Reading this corrupted area as a sequence of bytes, I saw that someone had written the C string "stop" to the DB, causing the corruption. I then searched for "stop" to find the code that caused the issue. Here was my fix, which didn’t touch SQLite code at all and instead ensured that, in this code, writes to a file descriptor only happen on the thread that will close the file descriptor.

I haven’t done a public-facing writeup on this, but this public-facing writeup shows how to solve a harder version of the same bug.

20:08 Reply: SIGBUS errors in HHVM (artifact: 269b7f3a68 user: jhemphill)

Yes, the *-shm file left on disk is zero bytes in size after a SIGBUS error.

01:20 Reply: SIGBUS errors in HHVM (artifact: 6a47060913 user: jhemphill)

I'll get back to you when I have a reliable answer to this question😅

01:20 Reply: SIGBUS errors in HHVM (artifact: 586d71875c user: jhemphill)

Our developers have their SQLite DBs on local disks running Btrfs. Developers do occasionally run into SQLITE_IOERR errors when writing to disk.

00:09 Post: SIGBUS errors in HHVM (artifact: f50b8e95bd user: jhemphill)

Hi all. I work on HHVM, Facebook's PHP JIT compiler. We're currently on SQLite 3.30, and we've been noticing rare SIGBUS errors blaming within SQLite code. The stack trace tends to look like this:

HPHP::Facts::(anonymous namespace)::AutoloadDBImpl::analyze()

I'm simply executing a prepared ANALYZE query statement. The DB is stored on a disk that has plenty of free space left.

I don't have a reproducible repro, but I'm mostly asking exploratory questions at this stage.

How can we prevent these SIGBUS errors in our application? I saw that, in 2012, this ticket in 2012 led to this bugfix in SQLite's code. Could this potentially be a bug in SQLite that we can help triage?

Thank you!