]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] make default_backend work in TCP mode too
authorWilly Tarreau <w@1wt.eu>
Sat, 3 Nov 2007 13:28:39 +0000 (14:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 3 Nov 2007 13:28:39 +0000 (14:28 +0100)
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.

src/client.c
tests/test-retries.cfg

index afba13ec77338c539fba5bc1afff6b6bc2fdcb70..2d7d16e59e6f561df60c671085a8d5e4925b7b85 100644 (file)
@@ -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 <p>, <p>, and later <be> and <be>.
@@ -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++;
 
index bd25e427c0e13ce8525b98d296d60246a54f8e09..588812c30d40c153cd93c8af7b1596ebb15cc236 100644 (file)
@@ -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