From c931a7aec5ccb2209d3c4bcf4452c807fe894d94 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 17 Dec 2010 17:23:15 +0000 Subject: * Do a short sleep after SQLITE_BUSY. --- src/libstore/local-store.cc | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/libstore') 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 #include #include +#include #include @@ -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 -- cgit 1.4.1