From: Vsevolod Stakhov Date: Sat, 25 Nov 2017 12:50:02 +0000 (+0000) Subject: [Fix] Do not try to connect to non-supported addresses X-Git-Tag: 1.7.0~411 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6af040cf2949ce0eebe52121efef6bb3ce4bcc54;p=rspamd.git [Fix] Do not try to connect to non-supported addresses --- 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) {