diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-26 14:02:41 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-10-26 14:02:41 +0000 |
commit | 0ae2f7f92758d468a24f05dfe95ffaa97ed4513c (patch) | |
tree | 0a445cabfe4bf32f2094d309715f28c6c9d086d2 /src/libstat/backends/sqlite3_backend.c | |
parent | c6eb33fa9c32101c6519e7b69a1bb92ab29524f8 (diff) | |
download | rspamd-0ae2f7f92758d468a24f05dfe95ffaa97ed4513c.tar.gz rspamd-0ae2f7f92758d468a24f05dfe95ffaa97ed4513c.zip |
Avoid endless loop when cannot open sqlite db.
Diffstat (limited to 'src/libstat/backends/sqlite3_backend.c')
-rw-r--r-- | src/libstat/backends/sqlite3_backend.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/libstat/backends/sqlite3_backend.c b/src/libstat/backends/sqlite3_backend.c index a978f5753..47318d766 100644 --- a/src/libstat/backends/sqlite3_backend.c +++ b/src/libstat/backends/sqlite3_backend.c @@ -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) { |