From: Christopher Faulet Date: Tue, 7 Feb 2023 10:09:15 +0000 (+0100) Subject: MINOR: channel/stconn: Move rto/wto from the channel to the stconn X-Git-Tag: v2.8-dev5~134 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ed7e66fe1a316c5344e10da9d3433ad67d2ce866;p=thirdparty%2Fhaproxy.git MINOR: channel/stconn: Move rto/wto from the channel to the stconn 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 --- diff --git a/include/haproxy/channel-t.h b/include/haproxy/channel-t.h index ef4848bc3f..9bd4933455 100644 --- a/include/haproxy/channel-t.h +++ b/include/haproxy/channel-t.h @@ -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) */ }; diff --git a/include/haproxy/stconn-t.h b/include/haproxy/stconn-t.h index 61996f8048..526b29be15 100644 --- a/include/haproxy/stconn-t.h +++ b/include/haproxy/stconn-t.h @@ -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) */ diff --git a/src/cli.c b/src/cli.c index c38efa03b2..acaaaae4bc 100644 --- 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; diff --git a/src/dns.c b/src/dns.c index 883c293d4a..0494abaf4b 100644 --- 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; diff --git a/src/hlua.c b/src/hlua.c index 3c196802b4..5ef1618f55 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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); diff --git a/src/http_ana.c b/src/http_ana.c index 3112491238..ac22e5aced 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -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; diff --git a/src/http_client.c b/src/http_client.c index c6fc6ba770..04e1367977 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -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 */ diff --git a/src/sink.c b/src/sink.c index 58bcf81ef5..035109f449 100644 --- a/src/sink.c +++ b/src/sink.c @@ -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; diff --git a/src/stconn.c b/src/stconn.c index 46cb163921..d478723681 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -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 */ diff --git a/src/stream.c b/src/stream.c index 40c1a52b37..0296bed82c 100644 --- a/src/stream.c +++ b/src/stream.c @@ -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; }