diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-11-25 12:50:02 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2017-11-25 12:50:02 +0000 |
commit | 6af040cf2949ce0eebe52121efef6bb3ce4bcc54 (patch) | |
tree | 869ca667a132933cdb3ebff1006986b04bb0a97d | |
parent | 65967cdddf5ff8d858ff070bdc7885482408d2b7 (diff) | |
download | rspamd-6af040cf2949ce0eebe52121efef6bb3ce4bcc54.tar.gz rspamd-6af040cf2949ce0eebe52121efef6bb3ce4bcc54.zip |
[Fix] Do not try to connect to non-supported addresses
-rw-r--r-- | contrib/hiredis/net.c | 4 | ||||
-rw-r--r-- | lualib/lua_redis.lua | 10 | ||||
-rw-r--r-- | src/libserver/fuzzy_backend_redis.c | 4 |
3 files changed, 17 insertions, 1 deletions
diff --git a/contrib/hiredis/net.c b/contrib/hiredis/net.c index e4aa920ad..6aada0a6f 100644 --- a/contrib/hiredis/net.c +++ b/contrib/hiredis/net.c @@ -310,6 +310,10 @@ static int _redisContextConnectTcp(redisContext *c, const char *addr, int port, memset(&hints,0,sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; + if (!blocking) { + /* Rspamd specific: never try to resolve on non-blocking conn requests */ + hints.ai_flags = AI_NUMERICHOST | AI_NUMERICSERV; + } /* Try with IPv6 if no IPv4 address was found. We do it in this order since * in a Redis client you can't afford to test if you have IPv6 connectivity diff --git a/lualib/lua_redis.lua b/lualib/lua_redis.lua index 7ecb3d424..eda8dc37f 100644 --- a/lualib/lua_redis.lua +++ b/lualib/lua_redis.lua @@ -479,10 +479,11 @@ local function rspamd_redis_make_request(task, redis_params, key, is_write, call end end + local ip_addr = addr:get_addr() local options = { task = task, callback = rspamd_redis_make_request_cb, - host = addr:get_addr(), + host = ip_addr, timeout = redis_params['timeout'], cmd = command, args = args @@ -497,6 +498,12 @@ local function rspamd_redis_make_request(task, redis_params, key, is_write, call end local ret,conn = rspamd_redis.make_request(options) + + if not ret then + addr:fail() + logger.warnx(task, "cannot make redis request to: %s", tostring(ip_addr)) + end + return ret,conn,addr end @@ -550,6 +557,7 @@ local function redis_make_request_taskless(ev_base, cfg, redis_params, key, is_w local ret,conn = rspamd_redis.make_request(options) if not ret then logger.errx('cannot execute redis request') + addr:fail() end return ret,conn,addr end diff --git a/src/libserver/fuzzy_backend_redis.c b/src/libserver/fuzzy_backend_redis.c index a660a8523..a44f116a8 100644 --- a/src/libserver/fuzzy_backend_redis.c +++ b/src/libserver/fuzzy_backend_redis.c @@ -649,6 +649,7 @@ rspamd_fuzzy_backend_check_redis (struct rspamd_fuzzy_backend *bk, rspamd_inet_address_get_port (addr)); if (session->ctx == NULL) { + rspamd_upstream_fail (up); rspamd_fuzzy_redis_session_dtor (session, TRUE); if (cb) { @@ -772,6 +773,7 @@ rspamd_fuzzy_backend_count_redis (struct rspamd_fuzzy_backend *bk, rspamd_inet_address_get_port (addr)); if (session->ctx == NULL) { + rspamd_upstream_fail (up); rspamd_fuzzy_redis_session_dtor (session, TRUE); if (cb) { @@ -894,6 +896,7 @@ rspamd_fuzzy_backend_version_redis (struct rspamd_fuzzy_backend *bk, rspamd_inet_address_get_port (addr)); if (session->ctx == NULL) { + rspamd_upstream_fail (up); rspamd_fuzzy_redis_session_dtor (session, TRUE); if (cb) { @@ -1326,6 +1329,7 @@ rspamd_fuzzy_backend_update_redis (struct rspamd_fuzzy_backend *bk, rspamd_inet_address_get_port (addr)); if (session->ctx == NULL) { + rspamd_upstream_fail (up); rspamd_fuzzy_redis_session_dtor (session, TRUE); if (cb) { |