]> source.dussan.org Git - rspamd.git/commitdiff
Avoid endless loop when cannot open sqlite db.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 26 Oct 2015 14:02:41 +0000 (14:02 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 26 Oct 2015 14:02:41 +0000 (14:02 +0000)
src/libstat/backends/sqlite3_backend.c

index a978f57531f8bacb569e40494fa205128b7f249a..47318d76693ec9db5cc8684e7d8f514c1771186d 100644 (file)
@@ -443,6 +443,8 @@ rspamd_sqlite3_opendb (rspamd_mempool_t *pool,
        gpointer tk_conf;
        gsize sz = 0;
        gchar *tok_conf_encoded;
+       gint ret, ntries = 0;
+       const gint max_tries = 100;
        struct timespec sleep_ts = {
                        .tv_sec = 0,
                        .tv_nsec = 1000000
@@ -471,11 +473,21 @@ rspamd_sqlite3_opendb (rspamd_mempool_t *pool,
 
        /* Check tokenizer configuration */
 
-       while (rspamd_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
-                       RSPAMD_STAT_BACKEND_TRANSACTION_START_EXCL) != SQLITE_OK) {
+       while ((ret = rspamd_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
+                       RSPAMD_STAT_BACKEND_TRANSACTION_START_EXCL)) == SQLITE_BUSY &&
+                       ++ntries <= max_tries) {
                nanosleep (&sleep_ts, NULL);
        }
 
+       if (ret != SQLITE_OK) {
+               msg_err_pool ("failed to stard transaction: %d, %s", ret,
+                               sqlite3_errmsg (bk->sqlite));
+               sqlite3_close (bk->sqlite);
+               g_slice_free1 (sizeof (*bk), bk);
+
+               return NULL;
+       }
+
        if (rspamd_sqlite3_run_prstmt (pool, bk->sqlite, bk->prstmt,
                        RSPAMD_STAT_BACKEND_LOAD_TOKENIZER, &sz, &tk_conf) != SQLITE_OK ||
                        sz == 0) {