1 commit 68265b3993d68cc7af5fc0f70bcfa35d52ffa99d
2 Author: Olivier Houchard <cognet@ci0.org>
3 Date: Mon Dec 30 15:13:42 2019 +0100
5 BUG/MEDIUM: checks: Only attempt to do handshakes if the connection is ready.
7 When creating a new check connection, only attempt to add an handshake
8 connection if the connection has fully been initialized. It can not be the
9 case if a DNS resolution is still pending, and thus we don't yet have the
10 address for the server, as the handshake code assumes the connection is fully
11 initialized and would otherwise crash.
12 This is not ideal, the check shouldn't probably run until we have an address,
13 as it leads to check failures with "Socket error".
14 While I'm there, also add an xprt handshake if we're using socks4, otherwise
15 checks wouldn't be able to use socks4 properly.
16 This should fix github issue #430
18 This should be backported to 2.0 and 2.1.
20 (cherry picked from commit 37d7897aafc412f3c4a4a68a1dccbd6b5d6cb180)
21 Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
23 diff --git a/src/checks.c b/src/checks.c
24 index 083aebbe0..2b7fc09c6 100644
27 @@ -1715,6 +1715,9 @@ static int connect_conn_chk(struct task *t)
28 if (s->check.send_proxy && !(check->state & CHK_ST_AGENT)) {
29 conn->send_proxy_ofs = 1;
30 conn->flags |= CO_FL_SEND_PROXY;
32 + if (conn->flags & (CO_FL_SEND_PROXY | CO_FL_SOCKS4) &&
33 + conn_ctrl_ready(conn)) {
34 if (xprt_add_hs(conn) < 0)
35 ret = SF_ERR_RESOURCE;
37 @@ -2960,7 +2963,8 @@ static int tcpcheck_main(struct check *check)
38 if (proto && proto->connect)
39 ret = proto->connect(conn,
40 CONNECT_HAS_DATA /* I/O polling is always needed */ | (next && next->action == TCPCHK_ACT_EXPECT) ? 0 : CONNECT_DELACK_ALWAYS);
41 - if (check->current_step->conn_opts & TCPCHK_OPT_SEND_PROXY) {
42 + if (conn_ctrl_ready(conn) &&
43 + check->current_step->conn_opts & TCPCHK_OPT_SEND_PROXY) {
44 conn->send_proxy_ofs = 1;
45 conn->flags |= CO_FL_SEND_PROXY;
46 if (xprt_add_hs(conn) < 0)