]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Make socket non-blocking before connect()
authorMikhail Galanin <mgalanin@mimecast.com>
Mon, 24 Sep 2018 14:27:57 +0000 (15:27 +0100)
committerMikhail Galanin <mgalanin@mimecast.com>
Mon, 24 Sep 2018 14:27:57 +0000 (15:27 +0100)
    Otherwise, in the case of error, socket may become invalid
    and we will get an incorrect error, i.e. "setsockopt(TCP_NODELAY): Invalid argument"
    instead of "Connection refused"

contrib/hiredis/net.c

index 6aada0a6f95ec4efb458f03d56efbb5f033e1dd1..c208eb10d85c684998e5c7cd506ab57a650859b2 100644 (file)
@@ -367,6 +367,10 @@ addrretry:
                 goto error;
             }
         }
+        if (blocking && redisSetBlocking(c,1) != REDIS_OK)
+            goto error;
+        if (redisSetTcpNoDelay(c) != REDIS_OK)
+            goto error;
         if (connect(s,p->ai_addr,p->ai_addrlen) == -1) {
             if (errno == EHOSTUNREACH) {
                 redisContextCloseFd(c);
@@ -384,10 +388,6 @@ addrretry:
                     goto error;
             }
         }
-        if (blocking && redisSetBlocking(c,1) != REDIS_OK)
-            goto error;
-        if (redisSetTcpNoDelay(c) != REDIS_OK)
-            goto error;
 
         c->flags |= REDIS_CONNECTED;
         rv = REDIS_OK;