From: Willy Tarreau Date: Sat, 3 Nov 2007 13:28:39 +0000 (+0100) Subject: [MEDIUM] make default_backend work in TCP mode too X-Git-Tag: v1.3.14~62 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a7e76142a1b9aae2ba91098c3ead6af3e1399467;p=thirdparty%2Fhaproxy.git [MEDIUM] make default_backend work in TCP mode too The default_backend did not work in TCP mode since there was no header state to assign the backend. This causes much trouble when configs are created by copy-paste. The solution was to fix the way the backend is assigned upon accept(). A wrong contimeout assignment was fixed too. --- diff --git a/src/client.c b/src/client.c index afba13ec77..2d7d16e59e 100644 --- a/src/client.c +++ b/src/client.c @@ -177,7 +177,25 @@ int event_accept(int fd) { s->task = t; s->be = s->fe = p; - s->cli_state = (p->mode == PR_MODE_HTTP) ? CL_STHEADERS : CL_STDATA; /* no HTTP headers for non-HTTP proxies */ + /* in HTTP mode, content switching requires that the backend + * first points to the same proxy as the frontend. However, in + * TCP mode there will be no header processing so any default + * backend must be assigned if set. + */ + if (p->mode == PR_MODE_HTTP) { + s->cli_state = CL_STHEADERS; + } else { + /* We must assign any default backend now since + * there will be no header processing. + */ + if (p->mode == PR_MODE_TCP) { + if (p->defbe.be) + s->be = p->defbe.be; + s->flags |= SN_BE_ASSIGNED; + } + s->cli_state = CL_STDATA; /* no HTTP headers for non-HTTP proxies */ + } + s->srv_state = SV_STIDLE; s->req = s->rep = NULL; /* will be allocated later */ @@ -185,7 +203,7 @@ int event_accept(int fd) { s->srv_fd = -1; s->srv = NULL; s->pend_pos = NULL; - s->conn_retries = p->conn_retries; + s->conn_retries = s->be->conn_retries; /* FIXME: the logs are horribly complicated now, because they are * defined in

,

, and later and . @@ -368,7 +386,7 @@ int event_accept(int fd) { s->req->rto = s->fe->clitimeout; s->req->wto = s->be->srvtimeout; - s->req->cto = s->be->srvtimeout; + s->req->cto = s->be->contimeout; if ((s->rep = pool_alloc2(pool2_buffer)) == NULL) { /* no memory */ pool_free2(pool2_buffer, s->req); @@ -444,6 +462,13 @@ int event_accept(int fd) { p->feconn++; /* beconn will be increased later */ if (p->feconn > p->feconn_max) p->feconn_max = p->feconn; + + if (s->flags & SN_BE_ASSIGNED) { + s->be->cum_beconn++; + s->be->beconn++; + if (s->be->beconn > s->be->beconn_max) + s->be->beconn_max = s->be->beconn; + } actconn++; totalconn++; diff --git a/tests/test-retries.cfg b/tests/test-retries.cfg index bd25e427c0..588812c30d 100644 --- a/tests/test-retries.cfg +++ b/tests/test-retries.cfg @@ -53,6 +53,23 @@ listen cookie_persist server dead1 1.1.1.1:80 cookie s1 server good1 127.0.0.1:80 cookie s1 +frontend frt_default_tcp + bind :8003 + mode tcp + option httplog + default_backend bck_default_tcp + +backend bck_default_tcp + mode tcp + option httplog + retries 2 + redispatch + balance roundrobin + contimeout 1000 + srvtimeout 25000 + server dead1 1.1.1.1:80 + server good1 127.0.0.1:80 + frontend frt_default bind :8004 mode http