about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--configure.ac3
-rw-r--r--src/libstore/local-store.cc11
2 files changed, 12 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac
index 2a8bedb0d1f6..46e825899c79 100644
--- a/configure.ac
+++ b/configure.ac
@@ -286,8 +286,7 @@ AC_CHECK_FUNCS([setresuid setreuid lchown])
 
 
 # Nice to have, but not essential.
-AC_CHECK_FUNCS([strsignal])
-AC_CHECK_FUNCS([posix_fallocate])
+AC_CHECK_FUNCS([strsignal posix_fallocate nanosleep])
 
 
 # This is needed if ATerm or bzip2 are static libraries,
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