I can now reliably corrupt my database - and this happens only when some
other process is writing to the database while I perform sqlite3_close_v2 on
the connections. I'll explain what I'm doing.

Since the last I wrote, I've disabled all the flags other than these:

#define SQLITE_ENABLE_FTS3 1
#define SQLITE_ENABLE_STAT4 1
#define SQLITE_DEFAULT_SYNCHRONOUS 1 // 1: Normal, 2: Full, 3: Extra
#define SQLITE_TEMP_STORE 3 // always use memory

It now assumes that sqlite is in serialised mode (and thus, thread safe).
I've removed all sorts of clever caching within the app and have simply two
connections in WAL mode (one for writing, one for reading). These are used
by various different threads, presumably at the same time but that should
not be an issue with sqlite in serialised mode.

This is how I can reproduce the malformed bug:

1) I have a bash script that runs in a loop:

#!/bin/bash
while :
do
  ls -alF
  sqlite3 mydb.db "CREATE TABLE IF NOT EXISTS junk (INTEGER a);"
  sqlite3 mydb.db "SELECT count(*) FROM junk;"
  sqlite3 mydb.db "SELECT count(*) FROM junk;INSERT INTO junk VALUES (1);"
  sqlite3 mydb.db "PRAGMA integrity_check;"

  sleep 0.5
done


2) I have my app running on the side. I launch it with a fresh copy of the
mydb.db for the app (pre-corruption, with data from the app in there
already). The app does it's thing (selecting / inserting data). I then quit
the app, at which point it closes the two connections with sqlite3_close_v2
*successfully*. 

3) 8/10, my bash script suddenly starts spewing this on the console:

Page 24256: btreeInitPage() returns error code 11
On tree page 722 cell 1: 2nd reference to page 24256
On tree page 932 cell 3: 2nd reference to page 24255

This happens only after I am able to close the connections successfully from
the app and the app successfully quits (connected to Xcode's debugger).

I have no idea what is going on since I've dumbed down the code to the point
where it's simply opening a connection at launch, closing it at termination.
I'm not using any extra mutex's within the app, assuming the sqlite works
correctly in serialised mode.

Please help!



--
Sent from: http://sqlite.1065341.n5.nabble.com/
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to