[sheepdog] [PATCH v3 2/3] net: fix embryonic connection handling in connect_to()

Liu Yuan namei.unix at gmail.com
Tue Sep 4 12:57:38 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

We should set_snd_timeout before calling connect() to avoid
embrynoic connection, which may remain in the half-open state for unbounded
periods of time (RFC 793). In this way, we don't need to switch to non-blocking
sockfd.

This prolem can be reproduced by 035.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 lib/net.c |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/lib/net.c b/lib/net.c
index 0970111..70954f0 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -229,6 +229,13 @@ int connect_to(const char *name, int port)
 			continue;
 		}
 
+		ret = set_snd_timeout(fd);
+		if (ret) {
+			eprintf("failed to set send timeout: %m\n");
+			close(fd);
+			break;
+		}
+
 		ret = connect(fd, res->ai_addr, res->ai_addrlen);
 		if (ret) {
 			eprintf("failed to connect to %s:%d: %m\n",
@@ -243,12 +250,6 @@ int connect_to(const char *name, int port)
 			break;
 		}
 
-		ret = set_snd_timeout(fd);
-		if (ret) {
-			close(fd);
-			break;
-		}
-
 		ret = set_nodelay(fd);
 		if (ret) {
 			eprintf("%m\n");
-- 
1.7.10.2




More information about the sheepdog mailing list