db locking issue

Matthias Andree matthias.andree at gmx.de
Thu Mar 24 22:03:28 CET 2005


Dmitry V. <vdb at mail.ru> writes:

> Hello, 
>
> I think I've found a bug in DB locking. I am using sqlite-3.2.0 database
> backend. Sometimes I get a messages in mail log like this: "Error preparing
> SELECT value... database is locked (#5)". I checked, it comes from
> datastore_sqlite.c line 266. Error code 5 means "database file is locked". I
> thought it should continue trying to connect to database untill it is unlocked. 

Ouch, hefty bug in sqlite before 3.2.0. Time to update SQLite
documentation and declare versions before 3.2.0 unsupported...

I'd found it hard to find information that would tell me a proper
reaction to this situation, but I can make the code sleep and retry.
How about this patch?

Index: src/datastore_sqlite.c
===================================================================
RCS file: /cvsroot/bogofilter/bogofilter/src/datastore_sqlite.c,v
retrieving revision 1.30
diff -u -r1.30 datastore_sqlite.c
--- src/datastore_sqlite.c	24 Mar 2005 01:26:53 -0000	1.30
+++ src/datastore_sqlite.c	24 Mar 2005 21:01:17 -0000
@@ -177,7 +177,16 @@
     bool loop, found;
     found = false;
     /* sqlite3_exec doesn't allow us to retrieve BLOBs */
-    rc = sqlite3_prepare(db, cmd, strlen(cmd), &stmt, &tail);
+    do {
+	rc = sqlite3_prepare(db, cmd, strlen(cmd), &stmt, &tail);
+	if (rc == SQLITE_LOCKED) {
+	    if (stmt)
+		sqlite3_finalize(stmt);
+	    if (DEBUG_DATABASE(2))
+		fprintf(dbgout, "database locked, sleeping and retrying...\n");
+	    rand_sleep(1000, 100000);
+	}
+    } while (rc == SQLITE_LOCKED);
     if (rc) {
 	print_error(__FILE__, __LINE__,
 		"Error preparing \"%s\": %s (#%d)\n",

-- 
Matthias Andree
_______________________________________________
Bogofilter mailing list
Bogofilter at bogofilter.org
http://www.bogofilter.org/mailman/listinfo/bogofilter



More information about the Bogofilter mailing list