]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stream-int/stream: Move conn_retries counter in the stream
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 29 Mar 2022 13:42:09 +0000 (15:42 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 13 Apr 2022 13:10:14 +0000 (15:10 +0200)
The conn_retries counter may be moved into the stream structure. It only
concerns the connection establishment. The frontend stream-interface does not
use it. So it is a logical change.

include/haproxy/stream-t.h
include/haproxy/stream.h
include/haproxy/stream_interface-t.h
include/haproxy/stream_interface.h
src/backend.c
src/cli.c
src/http_ana.c
src/log.c
src/stream.c

index 3fd5090fbe1ea61661b7417c0b91965bb31591e7..0fb5e7a8b987b6260fe56d8ec6a1e12546baa196 100644 (file)
@@ -80,7 +80,7 @@
 
 #define SF_SRV_REUSED   0x00100000     /* the server-side connection was reused */
 #define SF_SRV_REUSED_ANTICIPATED  0x00200000  /* the connection was reused but the mux is not ready yet */
-#define SF_WEBSOCKET    0x00400000     /* websocket stream */
+#define SF_WEBSOCKET    0x00400000     /* websocket stream */ // TODO: must be removed
 
 /* flags for the proxy of the master CLI */
 /* 0x0001.. to 0x8000 are reserved for ACCESS_* flags from cli-t.h */
@@ -139,6 +139,8 @@ struct stream {
        int16_t priority_class;         /* priority class of the stream for the pending queue */
        int32_t priority_offset;        /* priority offset of the stream for the pending queue */
 
+       int conn_retries;               /* number of connect retries left */
+
        struct list list;               /* position in the thread's streams list */
        struct mt_list by_srv;          /* position in server stream list */
        struct list back_refs;          /* list of users tracking this stream */
index 8024fcee6fe21daa515af1ee7cb9b75b9e109ccf..93093f74e303d6250a8e98823ada393ea7d9b631 100644 (file)
@@ -331,10 +331,10 @@ static inline void stream_choose_redispatch(struct stream *s)
            (s->be->options & PR_O_REDISP) && !(s->flags & SF_FORCE_PRST) &&
            ((__objt_server(s->target)->cur_state < SRV_ST_RUNNING) ||
             (((s->be->redispatch_after > 0) &&
-              ((s->be->conn_retries - si->conn_retries) %
+              ((s->be->conn_retries - s->conn_retries) %
                s->be->redispatch_after == 0)) ||
              ((s->be->redispatch_after < 0) &&
-              ((s->be->conn_retries - si->conn_retries) %
+              ((s->be->conn_retries - s->conn_retries) %
                (s->be->conn_retries + 1 + s->be->redispatch_after) == 0))) ||
             (!(s->flags & SF_DIRECT) && s->be->srv_act > 1 &&
              ((s->be->lbprm.algo & BE_LB_KIND) == BE_LB_KIND_RR)))) {
index 2e6ef39774ba8253d33457ee3b9c71a4ac7742d6..8ed3d4ed0b1b66eb21d586d52b4065f4d27a588e 100644 (file)
@@ -135,7 +135,6 @@ struct stream_interface {
 
        /* struct members below are the "remote" part, as seen from the buffer side */
        unsigned int err_type;  /* first error detected, one of SI_ET_* */
-       int conn_retries;       /* number of connect retries left */
 
        unsigned int hcto;      /* half-closed timeout (0 = unset) */
        struct wait_event wait_event; /* We're in a wait list */
index 60efe1de357419612751a832d2ea69099a5951f4..33d5e19f5daee2c98c9595fe0bae316c8e6442bb 100644 (file)
@@ -110,7 +110,6 @@ static inline int si_init(struct stream_interface *si)
        si->src            = NULL;
        si->dst            = NULL;
        si->err_type       = SI_ET_NONE;
-       si->conn_retries   = 0;  /* used for logging too */
        si->exp            = TICK_ETERNITY;
        si->flags         &= SI_FL_ISBACK;
        si->cs             = NULL;
@@ -376,7 +375,7 @@ static inline int si_connect(struct stream_interface *si, struct connection *con
 
        if (!channel_is_empty(si_oc(si)))
                conn_flags |= CONNECT_HAS_DATA;
-       if (si->conn_retries == si_strm(si)->be->conn_retries)
+       if (si_strm(si)->conn_retries == si_strm(si)->be->conn_retries)
                conn_flags |= CONNECT_CAN_USE_TFO;
        if (!conn_ctrl_ready(conn) || !conn_xprt_ready(conn)) {
                ret = conn->ctrl->connect(conn, conn_flags);
index a23aecf9b6cb291dfe3664e1ed2031a691111c31..d2d04d986f6ad7597370ae2af75e0cb4c6224b04 100644 (file)
@@ -1721,7 +1721,7 @@ skip_reuse:
             */
            ((cli_conn->flags & CO_FL_EARLY_DATA) ||
             ((s->be->retry_type & PR_RE_EARLY_ERROR) &&
-             cs_si(s->csb)->conn_retries == s->be->conn_retries)) &&
+             s->conn_retries == s->be->conn_retries)) &&
            !channel_is_empty(cs_oc(s->csb)) &&
            srv_conn->flags & CO_FL_SSL_WAIT_HS)
                srv_conn->flags &= ~(CO_FL_SSL_WAIT_HS | CO_FL_WAIT_L6_CONN);
@@ -2251,14 +2251,14 @@ void back_handle_st_cer(struct stream *s)
                         * provided by the client and we don't want to let the
                         * client provoke retries.
                         */
-                       cs->si->conn_retries = 0;
+                       s->conn_retries = 0;
                        DBG_TRACE_DEVEL("Bad SSL cert, disable connection retries", STRM_EV_STRM_PROC|STRM_EV_SI_ST|STRM_EV_STRM_ERR, s);
                }
        }
 
        /* ensure that we have enough retries left */
-       cs->si->conn_retries--;
-       if (cs->si->conn_retries < 0 || !(s->be->retry_type & PR_RE_CONN_FAILED)) {
+       s->conn_retries--;
+       if (s->conn_retries < 0 || !(s->be->retry_type & PR_RE_CONN_FAILED)) {
                if (!cs->si->err_type) {
                        cs->si->err_type = SI_ET_CONN_ERR;
                }
index 8ebd896732eaf47cf793972221ae38e5e4e83382..f3d05d80079b669b59cccca88fb7f9c3c7be64e6 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -2768,7 +2768,6 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
 
                cs_si(s->csb)->state = cs_si(s->csb)->prev_state = SI_ST_INI;
                cs_si(s->csb)->err_type = SI_ET_NONE;
-               cs_si(s->csb)->conn_retries = 0;  /* used for logging too */
                cs_si(s->csb)->exp = TICK_ETERNITY;
                cs_si(s->csb)->flags &= SI_FL_ISBACK | SI_FL_DONT_WAKE; /* we're in the context of process_stream */
                s->req.flags &= ~(CF_SHUTW|CF_SHUTW_NOW|CF_AUTO_CONNECT|CF_WRITE_ERROR|CF_STREAMER|CF_STREAMER_FAST|CF_NEVER_WAIT|CF_WROTE_DATA);
@@ -2776,6 +2775,7 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                s->flags &= ~(SF_DIRECT|SF_ASSIGNED|SF_ADDR_SET|SF_BE_ASSIGNED|SF_FORCE_PRST|SF_IGNORE_PRST);
                s->flags &= ~(SF_CURR_SESS|SF_REDIRECTABLE|SF_SRV_REUSED);
                s->flags &= ~(SF_ERR_MASK|SF_FINST_MASK|SF_REDISP);
+               s->conn_retries = 0;  /* used for logging too */
                /* reinitialise the current rule list pointer to NULL. We are sure that
                 * any rulelist match the NULL pointer.
                 */
index e56ee561cc9dc114304245deaccd3858ca6665c4..7a72a06773b3aee186d1b1a18eec431f20d889be 100644 (file)
@@ -1226,8 +1226,8 @@ static __inline int do_l7_retry(struct stream *s, struct stream_interface *si)
        struct channel *req, *res;
        int co_data;
 
-       si->conn_retries--;
-       if (si->conn_retries < 0)
+       s->conn_retries--;
+       if (s->conn_retries < 0)
                return -1;
 
        if (objt_server(s->target)) {
index cbb86e57b931f43d6270f52633e4e0daf82d6bba..c3b7d92bafbc08e33b8ca01c2c91126b3f0e9b62 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -2616,8 +2616,8 @@ int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t
                        case LOG_FMT_RETRIES:  // %rq
                                if (s_flags & SF_REDISP)
                                        LOGCHAR('+');
-                               ret = ltoa_o(((s && cs_si(s->csb)->conn_retries > 0)
-                                             ? (be->conn_retries - cs_si(s->csb)->conn_retries)
+                               ret = ltoa_o(((s && s->conn_retries > 0)
+                                             ? (be->conn_retries - s->conn_retries)
                                              : ((s && cs_si(s->csb)->state != SI_ST_INI) ? be->conn_retries : 0)),
                                             tmplog, dst + maxsize - tmplog);
                                if (ret == NULL)
@@ -3080,7 +3080,7 @@ void strm_log(struct stream *s)
        err = (s->flags & SF_REDISP) ||
               ((s->flags & SF_ERR_MASK) > SF_ERR_LOCAL) ||
              (((s->flags & SF_ERR_MASK) == SF_ERR_NONE) &&
-              (cs_si(s->csb)->conn_retries != s->be->conn_retries)) ||
+              (s->conn_retries != s->be->conn_retries)) ||
              ((sess->fe->mode == PR_MODE_HTTP) && s->txn && s->txn->status >= 500);
 
        if (!err && (sess->fe->options2 & PR_O2_NOLOGNORM))
index fe1e2c299b5e8e1903b748cd2060cc7acf232021..71460fe87a872859973838c15304d0a55b985b68 100644 (file)
@@ -212,7 +212,7 @@ static void strm_trace(enum trace_level level, uint64_t mask, const struct trace
        else {
                chunk_appendf(&trace_buf, " - t=%p s=(%p,0x%08x) si_f=(%p,0x%08x,0x%x) si_b=(%p,0x%08x,0x%x) retries=%d",
                              task, s, s->flags, si_f, si_f->flags, si_f->err_type,
-                             si_b, si_b->flags, si_b->err_type, si_b->conn_retries);
+                             si_b, si_b->flags, si_b->err_type, s->conn_retries);
        }
 
        if (src->verbosity == STRM_VERB_MINIMAL)
@@ -420,6 +420,7 @@ struct stream *stream_new(struct session *sess, struct conn_stream *cs, struct b
 
        s->task = t;
        s->pending_events = 0;
+       s->conn_retries = 0;
        t->process = process_stream;
        t->context = s;
        t->expire = TICK_ETERNITY;
@@ -2160,7 +2161,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                                 * perform a connection request.
                                 */
                                si_b->state = SI_ST_REQ; /* new connection requested */
-                               si_b->conn_retries = s->be->conn_retries;
+                               s->conn_retries = s->be->conn_retries;
                                if ((s->be->retry_type &~ PR_RE_CONN_FAILED) &&
                                    (s->be->mode == PR_MODE_HTTP) &&
                                    !(s->txn->flags & TX_D_L7_RETRY))
@@ -3154,7 +3155,7 @@ static int stats_dump_full_strm_to_buffer(struct conn_stream *cs, struct stream
 
                chunk_appendf(&trash,
                             "  flags=0x%x, conn_retries=%d, srv_conn=%p, pend_pos=%p waiting=%d epoch=%#x\n",
-                            strm->flags, strm->csb->si->conn_retries, strm->srv_conn, strm->pend_pos,
+                            strm->flags, strm->conn_retries, strm->srv_conn, strm->pend_pos,
                             LIST_INLIST(&strm->buffer_wait.list), strm->stream_epoch);
 
                chunk_appendf(&trash,