commit ff1f29c: [Fix] Important hiredis fixes
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Oct 22 15:21:06 UTC 2019
Author: Vsevolod Stakhov
Date: 2019-10-22 16:14:13 +0100
URL: https://github.com/rspamd/rspamd/commit/ff1f29cc7270742b8c1a24b8c72e4f3e9ba2b820 (HEAD -> master)
[Fix] Important hiredis fixes
Hiredis can return error in two ways:
- ctx is NULL and this path is usually handled properly
- ctx->err is not REDIS_OK and this path is totally missing in many places
This change should fix the both cases.
---
src/libserver/redis_pool.c | 2 +-
src/libstat/backends/redis_backend.c | 44 +++++++++++++++++++++++++++++++----
src/libstat/learn_cache/redis_cache.c | 17 +++++++++++++-
3 files changed, 57 insertions(+), 6 deletions(-)
diff --git a/src/libserver/redis_pool.c b/src/libserver/redis_pool.c
index 6c168b9d4..0d310d968 100644
--- a/src/libserver/redis_pool.c
+++ b/src/libserver/redis_pool.c
@@ -252,7 +252,7 @@ rspamd_redis_pool_new_connection (struct rspamd_redis_pool *pool,
if (ctx) {
if (ctx->err != REDIS_OK) {
- msg_err ("cannot connect to redis: %s", ctx->errstr);
+ msg_err ("cannot connect to redis %s (port %d): %s", ip, port, ctx->errstr);
redisAsyncFree (ctx);
return NULL;
diff --git a/src/libstat/backends/redis_backend.c b/src/libstat/backends/redis_backend.c
index 9118e3fc4..90afe66d3 100644
--- a/src/libstat/backends/redis_backend.c
+++ b/src/libstat/backends/redis_backend.c
@@ -1006,6 +1006,14 @@ rspamd_redis_async_stat_cb (struct rspamd_stat_async_elt *elt, gpointer d)
return;
}
+ else if (redis_ctx->err != REDIS_OK) {
+ msg_warn ("cannot connect to redis server %s: %s",
+ rspamd_inet_address_to_string_pretty (addr),
+ redis_ctx->errstr);
+ redisAsyncFree (redis_ctx);
+
+ return;
+ }
redisLibevAttach (redis_elt->event_loop, redis_ctx);
cbdata = g_malloc0 (sizeof (*cbdata));
@@ -1030,8 +1038,10 @@ rspamd_redis_async_stat_fin (struct rspamd_stat_async_elt *elt, gpointer d)
{
struct rspamd_redis_stat_elt *redis_elt = elt->ud;
- rspamd_redis_async_cbdata_cleanup (redis_elt->cbdata);
- redis_elt->cbdata = NULL;
+ if (redis_elt->cbdata != NULL) {
+ rspamd_redis_async_cbdata_cleanup (redis_elt->cbdata);
+ redis_elt->cbdata = NULL;
+ }
}
/* Called on connection termination */
@@ -1649,7 +1659,18 @@ rspamd_redis_runtime (struct rspamd_task *task,
}
if (rt->redis == NULL) {
- msg_err_task ("cannot connect redis");
+ msg_warn_task ("cannot connect to redis server %s: %s",
+ rspamd_inet_address_to_string_pretty (addr),
+ strerror (errno));
+ return NULL;
+ }
+ else if (rt->redis->err != REDIS_OK) {
+ msg_warn_task ("cannot connect to redis server %s: %s",
+ rspamd_inet_address_to_string_pretty (addr),
+ rt->redis->errstr);
+ redisAsyncFree (rt->redis);
+ rt->redis = NULL;
+
return NULL;
}
@@ -1811,7 +1832,22 @@ rspamd_redis_learn_tokens (struct rspamd_task *task, GPtrArray *tokens,
rspamd_inet_address_get_port (addr));
}
- g_assert (rt->redis != NULL);
+ if (rt->redis == NULL) {
+ msg_warn_task ("cannot connect to redis server %s: %s",
+ rspamd_inet_address_to_string_pretty (addr),
+ strerror (errno));
+
+ return FALSE;
+ }
+ else if (rt->redis->err != REDIS_OK) {
+ msg_warn_task ("cannot connect to redis server %s: %s",
+ rspamd_inet_address_to_string_pretty (addr),
+ rt->redis->errstr);
+ redisAsyncFree (rt->redis);
+ rt->redis = NULL;
+
+ return FALSE;
+ }
redisLibevAttach (task->event_loop, rt->redis);
rspamd_redis_maybe_auth (rt->ctx, rt->redis);
diff --git a/src/libstat/learn_cache/redis_cache.c b/src/libstat/learn_cache/redis_cache.c
index 82c354bb6..a76ad585c 100644
--- a/src/libstat/learn_cache/redis_cache.c
+++ b/src/libstat/learn_cache/redis_cache.c
@@ -396,7 +396,22 @@ rspamd_stat_cache_redis_runtime (struct rspamd_task *task,
rspamd_inet_address_get_port (addr));
}
- g_assert (rt->redis != NULL);
+ if (rt->redis == NULL) {
+ msg_warn_task ("cannot connect to redis server %s: %s",
+ rspamd_inet_address_to_string_pretty (addr),
+ strerror (errno));
+
+ return NULL;
+ }
+ else if (rt->redis->err != REDIS_OK) {
+ msg_warn_task ("cannot connect to redis server %s: %s",
+ rspamd_inet_address_to_string_pretty (addr),
+ rt->redis->errstr);
+ redisAsyncFree (rt->redis);
+ rt->redis = NULL;
+
+ return NULL;
+ }
redisLibevAttach (task->event_loop, rt->redis);
More information about the Commits
mailing list