From e637e15306f18e27767941be4670b7091056ccc4 Mon Sep 17 00:00:00 2001 From: Mikhail Galanin Date: Mon, 24 Sep 2018 15:27:57 +0100 Subject: [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" --- contrib/hiredis/net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/hiredis/net.c b/contrib/hiredis/net.c index 6aada0a6f..c208eb10d 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; -- cgit v1.2.3