]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: channel/stconn: Move rto/wto from the channel to the stconn
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 7 Feb 2023 10:09:15 +0000 (11:09 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 22 Feb 2023 13:52:15 +0000 (14:52 +0100)
Read and write timeouts concerns the I/O. Thus, it is logical to move it into
the stconn. At the end, the stream is responsible to detect the timeouts. So
it is logcial to have these values in the stconn and not in the SE
descriptor. But it may change depending on the recfactoring.

So, now:
  * scf->rto is used instead of req->rto
  * scf->wto is used instead of res->wto
  * scb->rto is used instead of res->rto
  * scb->wto is used instead of req->wto

include/haproxy/channel-t.h
include/haproxy/stconn-t.h
src/cli.c
src/dns.c
src/hlua.c
src/http_ana.c
src/http_client.c
src/sink.c
src/stconn.c
src/stream.c

index ef4848bc3fba3712d58e8e0bdf625232f3e54bf1..9bd4933455108c3a6ba0d2dcd9b8d154a67567af 100644 (file)
@@ -253,8 +253,6 @@ struct channel {
        unsigned long long total;       /* total data read */
        int rex;                        /* expiration date for a read, in ticks */
        int wex;                        /* expiration date for a write or connect, in ticks */
-       int rto;                        /* read timeout, in ticks */
-       int wto;                        /* write timeout, in ticks */
        int analyse_exp;                /* expiration date for current analysers (if set) */
 };
 
index 61996f8048e57476dbb55765e873f6c74d4eeee9..526b29be15b6d7d37ab6bac938eef24000a9a502 100644 (file)
@@ -231,6 +231,8 @@ struct stconn {
 
        unsigned int flags;                  /* SC_FL_* */
        unsigned int hcto;                   /* half-closed timeout (0 = unset) */
+       unsigned int rto;                    /* read timeout, in ticks */
+       unsigned int wto;                    /* write timeout, in ticks */
        struct wait_event wait_event;        /* We're in a wait list */
        struct sedesc *sedesc;               /* points to the stream endpoint descriptor */
        enum obj_type *app;                  /* points to the applicative point (stream or check) */
index c38efa03b2a963848d85f232893b3fa482da1106..acaaaae4bc6d281ef5d73c0bb54b83b42c0d97b7 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1597,7 +1597,7 @@ static int cli_parse_set_timeout(char **args, char *payload, struct appctx *appc
                if (res || timeout < 1)
                        return cli_err(appctx, "Invalid timeout value.\n");
 
-               s->req.rto = s->res.wto = 1 + MS_TO_TICKS(timeout*1000);
+               s->scf->rto = s->scf->wto = 1 + MS_TO_TICKS(timeout*1000);
                task_wakeup(s->task, TASK_WOKEN_MSG); // recompute timeouts
                return 1;
        }
@@ -2825,11 +2825,11 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                /* Now we can realign the response buffer */
                c_realign_if_empty(&s->res);
 
-               s->req.rto = strm_fe(s)->timeout.client;
-               s->req.wto = TICK_ETERNITY;
+               s->scf->rto = strm_fe(s)->timeout.client;
+               s->scf->wto = strm_fe(s)->timeout.client;
 
-               s->res.rto = TICK_ETERNITY;
-               s->res.wto = strm_fe(s)->timeout.client;
+               s->scb->rto = TICK_ETERNITY;
+               s->scb->wto = TICK_ETERNITY;
 
                s->req.rex = TICK_ETERNITY;
                s->req.wex = TICK_ETERNITY;
index 883c293d4a184baf9f9458fed5a92eb6305fb2c5..0494abaf4b76506fbe569f6e7141c39dca871a3b 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -838,7 +838,7 @@ static int dns_session_init(struct appctx *appctx)
        /* for rto and rex to eternity to not expire on idle recv:
         * We are using a syslog server.
         */
-       s->res.rto = TICK_ETERNITY;
+       s->scb->rto = TICK_ETERNITY;
        s->res.rex = TICK_ETERNITY;
 
        ds->appctx = appctx;
index 3c196802b49ec03efc377eb483dc547e2f88b21a..5ef1618f55fb5b666ba3c7bef14e6f9a353af9c6 100644 (file)
@@ -3016,10 +3016,8 @@ __LJMP static int hlua_socket_settimeout(struct lua_State *L)
        s = appctx_strm(container_of(peer, struct hlua_csk_ctx, xref)->appctx);
 
        s->sess->fe->timeout.connect = tmout;
-       s->req.rto = tmout;
-       s->req.wto = tmout;
-       s->res.rto = tmout;
-       s->res.wto = tmout;
+       s->scf->rto = s->scf->wto = tmout;
+       s->scb->rto = s->scb->wto = tmout;
        s->req.rex = tick_add_ifset(now_ms, tmout);
        s->req.wex = tick_add_ifset(now_ms, tmout);
        s->res.rex = tick_add_ifset(now_ms, tmout);
@@ -8086,7 +8084,7 @@ __LJMP static int hlua_txn_done(lua_State *L)
                channel_auto_close(req);
                channel_erase(req);
 
-               res->wex = tick_add_ifset(now_ms, res->wto);
+               res->wex = tick_add_ifset(now_ms, s->scf->wto);
                channel_auto_read(res);
                channel_auto_close(res);
                channel_shutr_now(res);
index 31124912380b5b02617741ca5679fee9d8b1d25f..ac22e5aced768ac624c281e0f604df091e28eee1 100644 (file)
@@ -4439,7 +4439,7 @@ int http_forward_proxy_resp(struct stream *s, int final)
                channel_auto_close(req);
                channel_htx_erase(req, htxbuf(&req->buf));
 
-               res->wex = tick_add_ifset(now_ms, res->wto);
+               res->wex = tick_add_ifset(now_ms, s->scf->wto);
                channel_auto_read(res);
                channel_auto_close(res);
                channel_shutr_now(res);
@@ -4493,7 +4493,7 @@ void http_reply_and_close(struct stream *s, short status, struct http_reply *msg
        }
 
 end:
-       s->res.wex = tick_add_ifset(now_ms, s->res.wto);
+       s->res.wex = tick_add_ifset(now_ms, s->scf->wto);
 
        /* At this staged, HTTP analysis is finished */
        s->req.analysers &= AN_REQ_FLT_END;
index c6fc6ba770e5181b09b43bffc9b37417ff3765dc..04e13679771617c33e6ba72bb14000f8a26dc5ec 100644 (file)
@@ -1059,8 +1059,8 @@ static int httpclient_applet_init(struct appctx *appctx)
        s = appctx_strm(appctx);
        s->target = target;
        /* set the "timeout server" */
-       s->req.wto = hc->timeout_server;
-       s->res.rto = hc->timeout_server;
+       s->scb->rto = hc->timeout_server;
+       s->scb->wto = hc->timeout_server;
 
        if (doresolve) {
                /* in order to do the set-dst we need to put the address on the front */
index 58bcf81ef589e75f941d3a616bdeb0a033ef2a91..035109f4490c36c55b96d45c7a566d672deb2b71 100644 (file)
@@ -328,7 +328,7 @@ static void sink_forward_io_handler(struct appctx *appctx)
         */
        sc_oc(sc)->rex = TICK_ETERNITY;
        /* rto should not change but it seems the case */
-       sc_oc(sc)->rto = TICK_ETERNITY;
+       sc_opposite(sc)->rto = TICK_ETERNITY;
 
        if (unlikely(sc_ic(sc)->flags & CF_SHUTW))
                goto close;
@@ -476,7 +476,7 @@ static void sink_forward_oc_io_handler(struct appctx *appctx)
         */
        sc_oc(sc)->rex = TICK_ETERNITY;
        /* rto should not change but it seems the case */
-       sc_oc(sc)->rto = TICK_ETERNITY;
+       sc_opposite(sc)->rto = TICK_ETERNITY;
 
        /* an error was detected */
        if (unlikely(sc_ic(sc)->flags & CF_SHUTW))
@@ -635,7 +635,7 @@ static int sink_forward_session_init(struct appctx *appctx)
        /* for rto and rex to eternity to not expire on idle recv:
         * We are using a syslog server.
         */
-       s->res.rto = TICK_ETERNITY;
+       s->scb->rto = TICK_ETERNITY;
        s->res.rex = TICK_ETERNITY;
        sft->appctx = appctx;
 
index 46cb1639218b07d9430f99e63349eb93ff11b1d8..d478723681fa43f5f7a643752b36ebb7c0b88c36 100644 (file)
@@ -133,7 +133,7 @@ static struct stconn *sc_new(struct sedesc *sedesc)
        sc->obj_type = OBJ_TYPE_SC;
        sc->flags = SC_FL_NONE;
        sc->state = SC_ST_INI;
-       sc->hcto = TICK_ETERNITY;
+       sc->rto = sc->wto = sc->hcto = TICK_ETERNITY;
        sc->app = NULL;
        sc->app_ops = NULL;
        sc->src = NULL;
@@ -569,8 +569,8 @@ static void sc_app_shutw(struct stconn *sc)
        oc->wex = TICK_ETERNITY;
 
        if (tick_isset(sc->hcto)) {
-               ic->rto = sc->hcto;
-               ic->rex = tick_add(now_ms, ic->rto);
+               sc->rto = sc->hcto;
+               ic->rex = tick_add(now_ms, sc->rto);
        }
 
        switch (sc->state) {
@@ -648,7 +648,7 @@ static void sc_app_chk_snd(struct stconn *sc)
         */
        sc_ep_clr(sc, SE_FL_WAIT_DATA);
        if (!tick_isset(oc->wex))
-               oc->wex = tick_add_ifset(now_ms, oc->wto);
+               oc->wex = tick_add_ifset(now_ms, sc->wto);
 
        if (!(sc->flags & SC_FL_DONT_WAKE))
                task_wakeup(sc_strm_task(sc), TASK_WOKEN_IO);
@@ -710,8 +710,8 @@ static void sc_app_shutw_conn(struct stconn *sc)
        oc->wex = TICK_ETERNITY;
 
        if (tick_isset(sc->hcto)) {
-               ic->rto = sc->hcto;
-               ic->rex = tick_add(now_ms, ic->rto);
+               sc->rto = sc->hcto;
+               ic->rex = tick_add(now_ms, sc->rto);
        }
 
        switch (sc->state) {
@@ -843,7 +843,7 @@ static void sc_app_chk_snd_conn(struct stconn *sc)
                 */
                sc_ep_clr(sc, SE_FL_WAIT_DATA);
                if (!tick_isset(oc->wex))
-                       oc->wex = tick_add_ifset(now_ms, oc->wto);
+                       oc->wex = tick_add_ifset(now_ms, sc->wto);
        }
 
        if (likely(oc->flags & CF_WRITE_EVENT)) {
@@ -851,7 +851,7 @@ static void sc_app_chk_snd_conn(struct stconn *sc)
 
                /* update timeout if we have written something */
                if (!(oc->flags & CF_SHUTW) && !channel_is_empty(oc))
-                       oc->wex = tick_add_ifset(now_ms, oc->wto);
+                       oc->wex = tick_add_ifset(now_ms, sc->wto);
 
                if (tick_isset(ic->rex) && !(sc->flags & SC_FL_INDEP_STR)) {
                        /* Note: to prevent the client from expiring read timeouts
@@ -862,7 +862,7 @@ static void sc_app_chk_snd_conn(struct stconn *sc)
                         * of data which can full the socket buffers long before a
                         * write timeout is detected.
                         */
-                       ic->rex = tick_add_ifset(now_ms, ic->rto);
+                       ic->rex = tick_add_ifset(now_ms, sc->rto);
                }
        }
 
@@ -935,8 +935,8 @@ static void sc_app_shutw_applet(struct stconn *sc)
        oc->wex = TICK_ETERNITY;
 
        if (tick_isset(sc->hcto)) {
-               ic->rto = sc->hcto;
-               ic->rex = tick_add(now_ms, ic->rto);
+               sc->rto = sc->hcto;
+               ic->rex = tick_add(now_ms, sc->rto);
        }
 
        /* on shutw we always wake the applet up */
@@ -1009,7 +1009,7 @@ static void sc_app_chk_snd_applet(struct stconn *sc)
                return;
 
        if (!tick_isset(oc->wex))
-               oc->wex = tick_add_ifset(now_ms, oc->wto);
+               oc->wex = tick_add_ifset(now_ms, sc->wto);
 
        if (!channel_is_empty(oc)) {
                /* (re)start sending */
@@ -1043,7 +1043,7 @@ void sc_update_rx(struct stconn *sc)
        if ((ic->flags & CF_EOI) || sc->flags & (SC_FL_WONT_READ|SC_FL_NEED_BUFF|SC_FL_NEED_ROOM))
                ic->rex = TICK_ETERNITY;
        else if (!tick_isset(ic->rex))
-               ic->rex = tick_add_ifset(now_ms, ic->rto);
+               ic->rex = tick_add_ifset(now_ms, sc->rto);
 
        sc_chk_rcv(sc);
 }
@@ -1083,7 +1083,7 @@ void sc_update_tx(struct stconn *sc)
         */
        sc_ep_clr(sc, SE_FL_WAIT_DATA);
        if (!tick_isset(oc->wex)) {
-               oc->wex = tick_add_ifset(now_ms, oc->wto);
+               oc->wex = tick_add_ifset(now_ms, sc->wto);
                if (tick_isset(ic->rex) && !(sc->flags & SC_FL_INDEP_STR)) {
                        /* Note: depending on the protocol, we don't know if we're waiting
                         * for incoming data or not. So in order to prevent the socket from
@@ -1091,7 +1091,7 @@ void sc_update_tx(struct stconn *sc)
                         * except if it was already infinite or if we have explicitly setup
                         * independent streams.
                         */
-                       ic->rex = tick_add_ifset(now_ms, ic->rto);
+                       ic->rex = tick_add_ifset(now_ms, sc->rto);
                }
        }
 }
@@ -1136,11 +1136,11 @@ static void sc_notify(struct stconn *sc)
                if (sc_ep_test(sc, SE_FL_ERR_PENDING|SE_FL_ERROR) &&
                    !channel_is_empty(oc))
                        if (tick_isset(oc->wex))
-                               oc->wex = tick_add_ifset(now_ms, oc->wto);
+                               oc->wex = tick_add_ifset(now_ms, sc->wto);
 
                if (!(sc->flags & SC_FL_INDEP_STR))
                        if (tick_isset(ic->rex))
-                               ic->rex = tick_add_ifset(now_ms, ic->rto);
+                               ic->rex = tick_add_ifset(now_ms, sc->rto);
        }
 
        if (oc->flags & CF_DONT_READ)
@@ -1195,7 +1195,7 @@ static void sc_notify(struct stconn *sc)
        else if ((ic->flags & (CF_SHUTR|CF_READ_EVENT)) == CF_READ_EVENT) {
                /* we must re-enable reading if sc_chk_snd() has freed some space */
                if (tick_isset(ic->rex))
-                       ic->rex = tick_add_ifset(now_ms, ic->rto);
+                       ic->rex = tick_add_ifset(now_ms, sc->rto);
        }
 
        /* wake the task up only when needed */
index 40c1a52b3722c18ace3675062a75ddf4dbdebdbc..0296bed82c671f7787d2b3221be395f9616d0b6c 100644 (file)
@@ -517,8 +517,8 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
                channel_auto_close(&s->req);    /* let the producer forward close requests */
        }
 
-       s->req.rto = sess->fe->timeout.client;
-       s->req.wto = TICK_ETERNITY;
+       s->scf->rto = sess->fe->timeout.client;
+       s->scf->wto = sess->fe->timeout.client;
        s->req.rex = TICK_ETERNITY;
        s->req.wex = TICK_ETERNITY;
        s->req.analyse_exp = TICK_ETERNITY;
@@ -532,8 +532,8 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
                s->res.flags |= CF_NEVER_WAIT;
        }
 
-       s->res.wto = sess->fe->timeout.client;
-       s->res.rto = TICK_ETERNITY;
+       s->scb->wto = TICK_ETERNITY;
+       s->scb->rto = TICK_ETERNITY;
        s->res.rex = TICK_ETERNITY;
        s->res.wex = TICK_ETERNITY;
        s->res.analyse_exp = TICK_ETERNITY;
@@ -854,7 +854,7 @@ void stream_retnclose(struct stream *s, const struct buffer *msg)
        if (likely(msg && msg->data))
                co_inject(oc, msg->area, msg->data);
 
-       oc->wex = tick_add_ifset(now_ms, oc->wto);
+       oc->wex = tick_add_ifset(now_ms, s->scf->wto);
        channel_auto_read(oc);
        channel_auto_close(oc);
        channel_shutr_now(oc);
@@ -864,8 +864,8 @@ int stream_set_timeout(struct stream *s, enum act_timeout_name name, int timeout
 {
        switch (name) {
        case ACT_TIMEOUT_SERVER:
-               s->req.wto = timeout;
-               s->res.rto = timeout;
+               s->scb->wto = timeout;
+               s->scb->rto = timeout;
                return 1;
 
        case ACT_TIMEOUT_TUNNEL:
@@ -936,10 +936,10 @@ static void back_establish(struct stream *s)
                 * if already defined, it means that a set-timeout rule has
                 * been executed so do not overwrite them
                 */
-               if (!tick_isset(req->wto))
-                       req->wto = s->be->timeout.server;
-               if (!tick_isset(rep->rto))
-                       rep->rto = s->be->timeout.server;
+               if (!tick_isset(s->scb->wto))
+                       s->scb->wto = s->be->timeout.server;
+               if (!tick_isset(s->scb->rto))
+                       s->scb->rto = s->be->timeout.server;
                if (!tick_isset(s->tunnel_timeout))
                        s->tunnel_timeout = s->be->timeout.tunnel;
 
@@ -2422,22 +2422,22 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                 * the half-closed timeouts as well.
                 */
                if (!req->analysers && s->tunnel_timeout) {
-                       req->rto = req->wto = res->rto = res->wto =
+                       scf->rto = scf->wto = scb->rto = scb->wto =
                                s->tunnel_timeout;
 
                        if ((req->flags & CF_SHUTR) && tick_isset(sess->fe->timeout.clientfin))
-                               res->wto = sess->fe->timeout.clientfin;
+                               scf->wto = sess->fe->timeout.clientfin;
                        if ((req->flags & CF_SHUTW) && tick_isset(s->be->timeout.serverfin))
-                               res->rto = s->be->timeout.serverfin;
+                               scb->rto = s->be->timeout.serverfin;
                        if ((res->flags & CF_SHUTR) && tick_isset(s->be->timeout.serverfin))
-                               req->wto = s->be->timeout.serverfin;
+                               scb->wto = s->be->timeout.serverfin;
                        if ((res->flags & CF_SHUTW) && tick_isset(sess->fe->timeout.clientfin))
-                               req->rto = sess->fe->timeout.clientfin;
+                               scf->rto = sess->fe->timeout.clientfin;
 
-                       req->rex = tick_add(now_ms, req->rto);
-                       req->wex = tick_add(now_ms, req->wto);
-                       res->rex = tick_add(now_ms, res->rto);
-                       res->wex = tick_add(now_ms, res->wto);
+                       req->rex = tick_add(now_ms, scf->rto);
+                       req->wex = tick_add(now_ms, scb->wto);
+                       res->rex = tick_add(now_ms, scb->rto);
+                       res->wex = tick_add(now_ms, scf->wto);
                }
        }
 
@@ -3929,7 +3929,7 @@ static int smp_fetch_cur_server_timeout(const struct arg *args, struct sample *s
        if (!smp->strm)
                return 0;
 
-       smp->data.u.sint = TICKS_TO_MS(smp->strm->res.rto);
+       smp->data.u.sint = TICKS_TO_MS(smp->strm->scb->rto);
        return 1;
 }