about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-12-17T17·23+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-12-17T17·23+0000
commitc931a7aec5ccb2209d3c4bcf4452c807fe894d94 (patch)
tree5c70568f4cdd0912fbac71770c2cf915965ee79b /src
parentb1eb25217217087cb70a730da5311bd0890cf6ad (diff)
* Do a short sleep after SQLITE_BUSY.
Diffstat (limited to 'src')
-rw-r--r--src/libstore/local-store.cc11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc
index 56d05c7bb55c..6af34cc77814 100644
--- a/src/libstore/local-store.cc
+++ b/src/libstore/local-store.cc
@@ -16,6 +16,7 @@
 #include <fcntl.h>
 #include <errno.h>
 #include <stdio.h>
+#include <time.h>
 
 #include <sqlite3.h>
 
@@ -35,6 +36,16 @@ static void throwSQLiteError(sqlite3 * db, const format & f)
     int err = sqlite3_errcode(db);
     if (err == SQLITE_BUSY) {
         printMsg(lvlError, "warning: SQLite database is busy");
+        /* Sleep for a while since retrying the transaction right away
+           is likely to fail again. */
+#if HAVE_NANOSLEEP
+        struct timespec t;
+        t.tv_sec = 0;
+        t.tv_nsec = 100 * 1000 * 1000; /* 0.1s */
+        nanosleep(&t, 0);
+#else
+        sleep(1);
+#endif
         throw SQLiteBusy(format("%1%: %2%") % f.str() % sqlite3_errmsg(db));
     }
     else