]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] move QUEUE and TAR timers to stream interfaces
authorWilly Tarreau <w@1wt.eu>
Wed, 3 Sep 2008 16:11:02 +0000 (18:11 +0200)
committerWilly Tarreau <w@1wt.eu>
Sun, 2 Nov 2008 09:19:09 +0000 (10:19 +0100)
It was not practical to have QUEUE and TAR timers in buffers, as they caused
triggering of the timeout flags. Move them to the stream interface where they
belong.

include/types/stream_interface.h
src/backend.c
src/client.c
src/proto_http.c

index f976565f9ecf97c738f9e3ed4f5f90f9f43a2fa7..cd7fb706a296d9211533d05179ef0c6346c8348e 100644 (file)
@@ -61,6 +61,7 @@ struct stream_interface {
        unsigned int prev_state;/* SI_ST*, copy of previous state */
        void *owner;            /* generally a (struct task*) */
        int fd;                 /* file descriptor for a stream driver when known */
+       unsigned int exp;       /* wake up time for connect, queue, turn-around, ... */
        int (*shutw)(struct stream_interface *);  /* shutw function */
        struct buffer *ib, *ob; /* input and output buffers */
        unsigned int err_type;  /* first error detected, one of SI_ET_* */
index 16b2cc9dfabe25dc64513fb23076901bd6101a0c..4d855dba1d92f8c5976a5ef2e17fc881853d7dd4 100644 (file)
@@ -1997,7 +1997,7 @@ int srv_redispatch_connect(struct session *t)
                return 1;
 
        case SRV_STATUS_QUEUED:
-               t->req->wex = tick_add_ifset(now_ms, t->be->timeout.queue);
+               t->req->cons->exp = tick_add_ifset(now_ms, t->be->timeout.queue);
                t->req->cons->state = SI_ST_QUE;
                /* do nothing else and do not wake any other session up */
                return 1;
index 953e41ee2ce6b687e72410ca8822fd43c7b41d44..32e90ba4edeef344234d6c1cea22dc8ea42d3da0 100644 (file)
@@ -170,19 +170,21 @@ int event_accept(int fd) {
                s->cli_state = CL_STDATA;
                s->req = s->rep = NULL; /* will be allocated later */
 
-               s->si[0].state = SI_ST_EST;
+               s->si[0].state = s->si[0].prev_state = SI_ST_EST;
                s->si[0].err_type = SI_ET_NONE;
                s->si[0].err_loc = NULL;
                s->si[0].owner = t;
                s->si[0].shutw = stream_sock_shutw;
                s->si[0].fd = cfd;
+               s->si[0].exp = TICK_ETERNITY;
                s->cli_fd = cfd;
 
-               s->si[1].state = SI_ST_INI;
+               s->si[1].state = s->si[1].prev_state = SI_ST_INI;
                s->si[1].err_type = SI_ET_NONE;
                s->si[1].err_loc = NULL;
                s->si[1].owner = t;
                s->si[1].shutw = stream_sock_shutw;
+               s->si[1].exp = TICK_ETERNITY;
                s->si[1].fd = -1; /* just to help with debugging */
 
                s->srv = s->prev_srv = s->srv_conn = NULL;
index 09cf587704273e68fbd036cd898e8772aebb36d2..0a09b2d1ebdb19a82c07f8899f952aab4d65c6cb 100644 (file)
@@ -671,6 +671,9 @@ void process_session(struct task *t, int *next)
                        if (tick_is_expired(s->req->analyse_exp, now_ms))
                                s->req->flags |= BF_ANA_TIMEOUT;
                }
+               /* Note that we don't check nor indicate if we wake up because
+                * of a timeout on a stream interface.
+                */
        }
 
        /* Check if we need to close the write side. This can only happen
@@ -908,6 +911,12 @@ void process_session(struct task *t, int *next)
                if (s->req->analysers)
                        t->expire = tick_first(t->expire, s->req->analyse_exp);
 
+               if (s->si[0].exp)
+                       t->expire = tick_first(t->expire, s->si[0].exp);
+
+               if (s->si[1].exp)
+                       t->expire = tick_first(t->expire, s->si[1].exp);
+
 #ifdef DEBUG_FULL
                fprintf(stderr, "[%u] queuing with exp=%u req->rex=%u req->wex=%u req->ana_exp=%u rep->rex=%u rep->wex=%u\n",
                        now_ms, t->expire, s->req->rex, s->req->wex, s->req->analyse_exp, s->rep->rex, s->rep->wex);
@@ -3613,7 +3622,7 @@ int tcp_connection_status(struct session *t)
                         * time of 1 second. We will wait in the previous if block.
                         */
                        req->cons->state = SI_ST_TAR;
-                       req->wex = tick_add(now_ms, MS_TO_TICKS(1000));
+                       req->cons->exp = tick_add(now_ms, MS_TO_TICKS(1000));
                        return 0;
                }
 
@@ -3731,7 +3740,7 @@ int stream_sock_assign_server(struct session *t)
                     (t->req->flags & BF_EMPTY || t->be->options & PR_O_ABRT_CLOSE))) { /* give up */
 
                        trace_term(t, TT_HTTP_SRV_1);
-                       t->req->wex = TICK_ETERNITY;
+                       t->req->cons->exp = TICK_ETERNITY;
 
                        // FIXME: should we set rep->MAY_FORWARD ?
                        buffer_shutr(t->rep);
@@ -3742,18 +3751,19 @@ int stream_sock_assign_server(struct session *t)
                        return 0;
                }
 
-               if (!tick_is_expired(t->req->wex, now_ms))
+               if (!tick_is_expired(t->req->cons->exp, now_ms))
                        return 0;  /* still in turn-around */
 
                t->req->cons->state = SI_ST_INI;
+               t->req->cons->exp = TICK_ETERNITY;
        }
        else if (t->req->cons->state == SI_ST_QUE) {
                if (t->pend_pos) {
                        /* request still in queue... */
-                       if (tick_is_expired(t->req->wex, now_ms)) {
+                       if (tick_is_expired(t->req->cons->exp, now_ms)) {
                                /* ... and timeout expired */
                                trace_term(t, TT_HTTP_SRV_3);
-                               t->req->wex = TICK_ETERNITY;
+                               t->req->cons->exp = TICK_ETERNITY;
                                t->logs.t_queue = tv_ms_elapsed(&t->logs.tv_accept, &now);
                                if (t->srv)
                                        t->srv->failed_conns++;
@@ -3775,7 +3785,7 @@ int stream_sock_assign_server(struct session *t)
                             (t->req->flags & BF_EMPTY || t->be->options & PR_O_ABRT_CLOSE))) {
                                /* give up */
                                trace_term(t, TT_HTTP_SRV_1);
-                               t->req->wex = TICK_ETERNITY;
+                               t->req->cons->exp = TICK_ETERNITY;
                                t->logs.t_queue = tv_ms_elapsed(&t->logs.tv_accept, &now);
 
                                // FIXME: should we set rep->MAY_FORWARD ?
@@ -3789,6 +3799,7 @@ int stream_sock_assign_server(struct session *t)
                }
                /* The connection is not in the queue anymore */
                t->req->cons->state = SI_ST_INI;
+               t->req->cons->exp = TICK_ETERNITY;
        }
 
        /* we may get here from above */
@@ -3802,7 +3813,6 @@ int stream_sock_assign_server(struct session *t)
                     (t->req->flags & BF_EMPTY || t->be->options & PR_O_ABRT_CLOSE))) { /* give up */
 
                        trace_term(t, TT_HTTP_SRV_1);
-                       t->req->wex = TICK_ETERNITY;
 
                        // FIXME: should we set rep->MAY_FORWARD ?
                        buffer_shutr(t->rep);
@@ -3822,7 +3832,6 @@ int stream_sock_assign_server(struct session *t)
                        }
 
                        trace_term(t, TT_HTTP_SRV_2);
-                       t->req->wex = TICK_ETERNITY;
 
                        // FIXME: should we set rep->MAY_FORWARD ?
                        buffer_shutr(t->rep);
@@ -3866,7 +3875,6 @@ int stream_sock_connect_server(struct session *t)
                if (t->req->cons->state != SI_ST_CON) {
                        /* it was an error */
                        trace_term(t, TT_HTTP_SRV_4);
-                       t->req->wex = TICK_ETERNITY;
 
                        // FIXME: should we set rep->MAY_FORWARD ?
                        buffer_shutr(t->rep);