]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: stconn: Replace read and write timeouts by a unique I/O timeout
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 15 Feb 2023 07:13:33 +0000 (08:13 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 22 Feb 2023 13:52:15 +0000 (14:52 +0100)
Read and write timeouts (.rto and .wto) are now replaced by an unique
timeout, call .ioto. Since the recent refactoring on channel's timeouts,
both use the same value, the client timeout on client side and the server
timeout on the server side. Thus, this part may be simplified. Now it
represents the I/O timeout.

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 ddaf733d63576100f28a3e4d581369dcfa93f664..5eddd8832d1c2aad553f1df16bd0bfd5e0aaf045 100644 (file)
@@ -235,8 +235,7 @@ 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 */
+       unsigned int ioto;                   /* I/O activity timeout */
        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 d1d5a56d34928464152ca51ed1971881f5eeec3e..b683652a303792014c5eec4481715c9d91ee2f3c 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->scf->rto = s->scf->wto = 1 + MS_TO_TICKS(timeout*1000);
+               s->scf->ioto = 1 + MS_TO_TICKS(timeout*1000);
                task_wakeup(s->task, TASK_WOKEN_MSG); // recompute timeouts
                return 1;
        }
@@ -2825,11 +2825,8 @@ 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->scf->rto = strm_fe(s)->timeout.client;
-               s->scf->wto = strm_fe(s)->timeout.client;
-
-               s->scb->rto = TICK_ETERNITY;
-               s->scb->wto = TICK_ETERNITY;
+               s->scf->ioto = strm_fe(s)->timeout.client;
+               s->scb->ioto = TICK_ETERNITY;
 
                sc_ep_reset_rex(s->scf);
                sc_ep_reset_wex(s->scf);
index d3114fb4f4469b263ec5eccd5e1d99a02a2ceb52..003169f61880f7e78e8f656a11828cb22afd7596 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -835,10 +835,9 @@ static int dns_session_init(struct appctx *appctx)
        s->uniq_id = 0;
 
        s->res.flags |= CF_READ_DONTWAIT;
-       /* for rto and rex to eternity to not expire on idle recv:
+       /* set rex to eternity to not expire on idle recv:
         * We are using a syslog server.
         */
-       s->scb->rto = TICK_ETERNITY;
        sc_ep_reset_rex(s->scb);
 
        ds->appctx = appctx;
index 864771aa9643643f2de4c6112bcf203b2ab2f1fc..1771d143c7512c21081d318f357d7814594af2b1 100644 (file)
@@ -3016,8 +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->scf->rto = s->scf->wto = tmout;
-       s->scb->rto = s->scb->wto = tmout;
+       s->scf->ioto = tmout;
+       s->scb->ioto = tmout;
        sc_ep_set_rex(s->scf, tmout);
        sc_ep_set_wex(s->scf, tmout);
        sc_ep_set_rex(s->scb, tmout);
@@ -8084,7 +8084,7 @@ __LJMP static int hlua_txn_done(lua_State *L)
                channel_auto_close(req);
                channel_erase(req);
 
-               sc_ep_set_wex(s->scb, s->scf->wto);
+               sc_ep_set_wex(s->scb, s->scf->ioto);
                channel_auto_read(res);
                channel_auto_close(res);
                channel_shutr_now(res);
index 3f156952793549a5afc2a17cbe3f80aa3819db0b..cc4163cdc1c83acada79d5b7c5c922b78b78e6a4 100644 (file)
@@ -4438,7 +4438,7 @@ int http_forward_proxy_resp(struct stream *s, int final)
                channel_auto_close(req);
                channel_htx_erase(req, htxbuf(&req->buf));
 
-               sc_ep_set_wex(s->scb, s->scf->wto);
+               sc_ep_set_wex(s->scb, s->scf->ioto);
                channel_auto_read(res);
                channel_auto_close(res);
                channel_shutr_now(res);
@@ -4492,7 +4492,7 @@ void http_reply_and_close(struct stream *s, short status, struct http_reply *msg
        }
 
 end:
-       sc_ep_set_wex(s->scb, s->scf->wto);
+       sc_ep_set_wex(s->scb, s->scf->ioto);
 
        /* At this staged, HTTP analysis is finished */
        s->req.analysers &= AN_REQ_FLT_END;
index 04e13679771617c33e6ba72bb14000f8a26dc5ec..a30a9416626cb4346dacf630d852eafd6bdc6244 100644 (file)
@@ -1059,8 +1059,7 @@ static int httpclient_applet_init(struct appctx *appctx)
        s = appctx_strm(appctx);
        s->target = target;
        /* set the "timeout server" */
-       s->scb->rto = hc->timeout_server;
-       s->scb->wto = hc->timeout_server;
+       s->scb->ioto = hc->timeout_server;
 
        if (doresolve) {
                /* in order to do the set-dst we need to put the address on the front */
index 8d52184142ec1c0f53230493dcadb730d1186565..d15de4ee618bc4507f89ee1379e304f327da311f 100644 (file)
@@ -327,8 +327,6 @@ static void sink_forward_io_handler(struct appctx *appctx)
         * with a syslog server
         */
        sc_ep_reset_rex(sc_opposite(sc));
-       /* rto should not change but it seems the case */
-       sc_opposite(sc)->rto = TICK_ETERNITY;
 
        if (unlikely(sc_ic(sc)->flags & CF_SHUTW))
                goto close;
@@ -475,8 +473,6 @@ static void sink_forward_oc_io_handler(struct appctx *appctx)
         * with a syslog server
         */
        sc_ep_reset_rex(sc_opposite(sc));
-       /* rto should not change but it seems the case */
-       sc_opposite(sc)->rto = TICK_ETERNITY;
 
        /* an error was detected */
        if (unlikely(sc_ic(sc)->flags & CF_SHUTW))
@@ -632,10 +628,9 @@ static int sink_forward_session_init(struct appctx *appctx)
        s->uniq_id = 0;
 
        s->res.flags |= CF_READ_DONTWAIT;
-       /* for rto and rex to eternity to not expire on idle recv:
+       /* Set rex to eternity to not expire on idle recv:
         * We are using a syslog server.
         */
-       s->scb->rto = TICK_ETERNITY;
        sc_ep_reset_rex(s->scb);
        sft->appctx = appctx;
 
index f834f70e1d550d1d2b451d0301cb2296acff2b0b..f65ae157efc6baa0bcae2d584e4cc2710cfba3eb 100644 (file)
@@ -134,7 +134,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->rto = sc->wto = sc->hcto = TICK_ETERNITY;
+       sc->ioto = sc->hcto = TICK_ETERNITY;
        sc->app = NULL;
        sc->app_ops = NULL;
        sc->src = NULL;
@@ -570,8 +570,8 @@ static void sc_app_shutw(struct stconn *sc)
        sc_ep_reset_wex(sc);
 
        if (tick_isset(sc->hcto)) {
-               sc->rto = sc->hcto;
-               sc_ep_set_rex(sc, sc->rto);
+               sc->ioto = sc->hcto;
+               sc_ep_set_rex(sc, sc->ioto);
        }
 
        switch (sc->state) {
@@ -649,7 +649,7 @@ static void sc_app_chk_snd(struct stconn *sc)
         */
        sc_ep_clr(sc, SE_FL_WAIT_DATA);
        if (!tick_isset(sc_ep_wex(sc)))
-               sc_ep_set_wex(sc, sc->wto);
+               sc_ep_set_wex(sc, sc->ioto);
 
        if (!(sc->flags & SC_FL_DONT_WAKE))
                task_wakeup(sc_strm_task(sc), TASK_WOKEN_IO);
@@ -711,8 +711,8 @@ static void sc_app_shutw_conn(struct stconn *sc)
        sc_ep_reset_wex(sc);
 
        if (tick_isset(sc->hcto)) {
-               sc->rto = sc->hcto;
-               sc_ep_set_rex(sc, sc->rto);
+               sc->ioto = sc->hcto;
+               sc_ep_set_rex(sc, sc->ioto);
        }
 
        switch (sc->state) {
@@ -844,13 +844,13 @@ static void sc_app_chk_snd_conn(struct stconn *sc)
                 */
                sc_ep_clr(sc, SE_FL_WAIT_DATA);
                if (!tick_isset(sc_ep_wex(sc)))
-                       sc_ep_set_wex(sc, sc->wto);
+                       sc_ep_set_wex(sc, sc->ioto);
        }
 
        if (likely(oc->flags & CF_WRITE_EVENT)) {
                /* update timeout if we have written something */
                if (!(oc->flags & CF_SHUTW) && !channel_is_empty(oc))
-                       sc_ep_set_wex(sc, sc->wto);
+                       sc_ep_set_wex(sc, sc->ioto);
 
                if (tick_isset(sc_ep_rex(sc)) && !(sc->flags & SC_FL_INDEP_STR)) {
                        /* Note: to prevent the client from expiring read timeouts
@@ -861,7 +861,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.
                         */
-                       sc_ep_set_rex(sc, sc->rto);
+                       sc_ep_set_rex(sc, sc->ioto);
                }
        }
 
@@ -934,8 +934,8 @@ static void sc_app_shutw_applet(struct stconn *sc)
        sc_ep_reset_wex(sc);
 
        if (tick_isset(sc->hcto)) {
-               sc->rto = sc->hcto;
-               sc_ep_set_rex(sc, sc->rto);
+               sc->ioto = sc->hcto;
+               sc_ep_set_rex(sc, sc->ioto);
        }
 
        /* on shutw we always wake the applet up */
@@ -1008,7 +1008,7 @@ static void sc_app_chk_snd_applet(struct stconn *sc)
                return;
 
        if (!tick_isset(sc_ep_wex(sc)))
-               sc_ep_set_wex(sc, sc->wto);
+               sc_ep_set_wex(sc, sc->ioto);
 
        if (!channel_is_empty(oc)) {
                /* (re)start sending */
@@ -1042,7 +1042,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))
                sc_ep_reset_rex(sc);
        else if (!tick_isset(sc_ep_rex(sc)))
-               sc_ep_set_rex(sc, sc->rto);
+               sc_ep_set_rex(sc, sc->ioto);
 
        sc_chk_rcv(sc);
 }
@@ -1081,7 +1081,7 @@ void sc_update_tx(struct stconn *sc)
         */
        sc_ep_clr(sc, SE_FL_WAIT_DATA);
        if (!tick_isset(sc_ep_wex(sc))) {
-               sc_ep_set_wex(sc, sc->wto);
+               sc_ep_set_wex(sc, sc->ioto);
                if (tick_isset(sc_ep_rex(sc)) && !(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
@@ -1089,7 +1089,7 @@ void sc_update_tx(struct stconn *sc)
                         * except if it was already infinite or if we have explicitly setup
                         * independent streams.
                         */
-                       sc_ep_set_rex(sc, sc->rto);
+                       sc_ep_set_rex(sc, sc->ioto);
                }
        }
 }
@@ -1134,11 +1134,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(sc_ep_wex(sc)))
-                               sc_ep_set_wex(sc, sc->wto);
+                               sc_ep_set_wex(sc, sc->ioto);
 
                if (!(sc->flags & SC_FL_INDEP_STR))
                        if (tick_isset(sc_ep_rex(sc)))
-                               sc_ep_set_rex(sc, sc->rto);
+                               sc_ep_set_rex(sc, sc->ioto);
        }
 
        if (oc->flags & CF_DONT_READ)
@@ -1193,7 +1193,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(sc_ep_rex(sc)))
-                       sc_ep_set_rex(sc, sc->rto);
+                       sc_ep_set_rex(sc, sc->ioto);
        }
 
        /* wake the task up only when needed */
index 0c8fad5472de6fad89cd3bb30e859d441d4f560d..96739fa46b36da4c7b4f98fd7bfb2c4b59b64853 100644 (file)
@@ -518,8 +518,7 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
                channel_auto_close(&s->req);    /* let the producer forward close requests */
        }
 
-       s->scf->rto = sess->fe->timeout.client;
-       s->scf->wto = sess->fe->timeout.client;
+       s->scf->ioto = sess->fe->timeout.client;
        s->req.analyse_exp = TICK_ETERNITY;
 
        channel_init(&s->res);
@@ -531,8 +530,7 @@ struct stream *stream_new(struct session *sess, struct stconn *sc, struct buffer
                s->res.flags |= CF_NEVER_WAIT;
        }
 
-       s->scb->wto = TICK_ETERNITY;
-       s->scb->rto = TICK_ETERNITY;
+       s->scb->ioto = TICK_ETERNITY;
        s->res.analyse_exp = TICK_ETERNITY;
 
        s->txn = NULL;
@@ -851,7 +849,7 @@ void stream_retnclose(struct stream *s, const struct buffer *msg)
        if (likely(msg && msg->data))
                co_inject(oc, msg->area, msg->data);
 
-       sc_ep_set_wex(s->scf, s->scf->wto);
+       sc_ep_set_wex(s->scf, s->scf->ioto);
        channel_auto_read(oc);
        channel_auto_close(oc);
        channel_shutr_now(oc);
@@ -861,8 +859,7 @@ int stream_set_timeout(struct stream *s, enum act_timeout_name name, int timeout
 {
        switch (name) {
        case ACT_TIMEOUT_SERVER:
-               s->scb->wto = timeout;
-               s->scb->rto = timeout;
+               s->scb->ioto = timeout;
                return 1;
 
        case ACT_TIMEOUT_TUNNEL:
@@ -933,10 +930,8 @@ 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(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->scb->ioto))
+                       s->scb->ioto = s->be->timeout.server;
                if (!tick_isset(s->tunnel_timeout))
                        s->tunnel_timeout = s->be->timeout.tunnel;
 
@@ -2419,22 +2414,17 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                 * the half-closed timeouts as well.
                 */
                if (!req->analysers && s->tunnel_timeout) {
-                       scf->rto = scf->wto = scb->rto = scb->wto =
-                               s->tunnel_timeout;
+                       scf->ioto = scb->ioto = s->tunnel_timeout;
 
-                       if ((req->flags & CF_SHUTR) && tick_isset(sess->fe->timeout.clientfin))
-                               scf->wto = sess->fe->timeout.clientfin;
-                       if ((req->flags & CF_SHUTW) && tick_isset(s->be->timeout.serverfin))
-                               scb->rto = s->be->timeout.serverfin;
-                       if ((res->flags & CF_SHUTR) && tick_isset(s->be->timeout.serverfin))
-                               scb->wto = s->be->timeout.serverfin;
-                       if ((res->flags & CF_SHUTW) && tick_isset(sess->fe->timeout.clientfin))
-                               scf->rto = sess->fe->timeout.clientfin;
+                       if ((req->flags & (CF_SHUTR|CF_SHUTW)) && tick_isset(sess->fe->timeout.clientfin))
+                               scf->ioto = sess->fe->timeout.clientfin;
+                       if ((req->flags & (CF_SHUTR|CF_SHUTW)) && tick_isset(s->be->timeout.serverfin))
+                               scb->ioto = s->be->timeout.serverfin;
 
-                       sc_ep_set_rex(scf, scf->rto);
-                       sc_ep_set_wex(scf, scb->wto);
-                       sc_ep_set_rex(scb, scb->rto);
-                       sc_ep_set_wex(scb, scf->wto);
+                       sc_ep_set_rex(scf, scf->ioto);
+                       sc_ep_set_wex(scf, scb->ioto);
+                       sc_ep_set_rex(scb, scb->ioto);
+                       sc_ep_set_wex(scb, scf->ioto);
                }
        }
 
@@ -3899,7 +3889,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->scb->rto);
+       smp->data.u.sint = TICKS_TO_MS(smp->strm->scb->ioto);
        return 1;
 }