From: Mikhail Galanin Date: Mon, 24 Sep 2018 14:27:57 +0000 (+0100) Subject: [Minor] Make socket non-blocking before connect() X-Git-Tag: 1.8.1~164^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e637e15306f18e27767941be4670b7091056ccc4;p=thirdparty%2Frspamd.git [Minor] Make socket non-blocking before connect() 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" --- diff --git a/contrib/hiredis/net.c b/contrib/hiredis/net.c index 6aada0a6f9..c208eb10d8 100644 --- a/contrib/hiredis/net.c +++ b/contrib/hiredis/net.c @@ -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;