]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: stconn: Always report READ/WRITE event on shutr/shutw
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 20 Feb 2023 06:55:19 +0000 (07:55 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 22 Feb 2023 14:59:16 +0000 (15:59 +0100)
It was done by hand by callers when a shutdown for read or write was
performed. It is now always handled by the functions performing the
shutdown. This way the callers don't take care of it. This will avoid some
bugs.

12 files changed:
addons/promex/service-prometheus.c
src/backend.c
src/cache.c
src/cli.c
src/dns.c
src/flt_spoe.c
src/hlua.c
src/log.c
src/peers.c
src/sink.c
src/stats.c
src/stconn.c

index 724d24b283407da52ab870fed485c82ffc2b3e20..e4cc469ee585baab934c4606f408ef73db028eb4 100644 (file)
@@ -1598,7 +1598,6 @@ static void promex_appctx_handle_io(struct appctx *appctx)
 
                case PROMEX_ST_END:
                        if (!(res->flags & CF_SHUTR)) {
-                               res->flags |= CF_READ_EVENT;
                                sc_shutr(sc);
                        }
        }
@@ -1614,7 +1613,6 @@ static void promex_appctx_handle_io(struct appctx *appctx)
        return;
 
   error:
-       res->flags |= CF_READ_EVENT;
        sc_shutr(sc);
        sc_shutw(sc);
        goto out;
index 5a35bcc99f81ae7668326eb3ba9c5458053050cd..d022627ad45b7f03d4f017210a742448c549a763 100644 (file)
@@ -2023,7 +2023,6 @@ void back_try_conn_req(struct stream *s)
                        sc_shutr(sc);
                        sc_shutw(sc);
                        sc_ep_set(sc, SE_FL_ERROR|SE_FL_EOS);
-                       req->flags |= CF_WRITE_EVENT;
 
                        s->logs.t_queue = tv_ms_elapsed(&s->logs.tv_accept, &now);
 
@@ -2184,7 +2183,6 @@ void back_handle_st_req(struct stream *s)
                        sc_shutr(sc);
                        sc_shutw(sc);
                        sc_ep_set(sc, SE_FL_ERROR|SE_FL_EOS);
-                       s->req.flags |= CF_WRITE_EVENT;
                        s->conn_err_type = STRM_ET_CONN_RES;
                        sc->state = SC_ST_CLO;
                        if (s->srv_error)
@@ -2211,7 +2209,6 @@ void back_handle_st_req(struct stream *s)
                sc_shutr(sc);
                sc_shutw(sc);
                sc_ep_set(sc, SE_FL_ERROR|SE_FL_EOS);
-               s->req.flags |= CF_WRITE_EVENT;
                if (!s->conn_err_type)
                        s->conn_err_type = STRM_ET_CONN_OTHER;
                sc->state = SC_ST_CLO;
@@ -2347,8 +2344,6 @@ void back_handle_st_cer(struct stream *s)
                /* shutw is enough to stop a connecting socket */
                sc_shutw(sc);
                sc_ep_set(sc, SE_FL_ERROR|SE_FL_EOS);
-               s->req.flags |= CF_WRITE_EVENT;
-               s->res.flags |= CF_READ_EVENT;
 
                sc->state = SC_ST_CLO;
                if (s->srv_error)
@@ -2382,8 +2377,6 @@ void back_handle_st_cer(struct stream *s)
                /* shutw is enough to stop a connecting socket */
                sc_shutw(sc);
                sc_ep_set(sc, SE_FL_ERROR|SE_FL_EOS);
-               s->req.flags |= CF_WRITE_EVENT;
-               s->res.flags |= CF_READ_EVENT;
 
                sc->state = SC_ST_CLO;
                if (s->srv_error)
index 9683c088af694c357c272a73350e2f24c2814d16..ae57ce544c30559cc1eebb3ee8f517bc3d91cf39 100644 (file)
@@ -1532,10 +1532,8 @@ static void http_cache_io_handler(struct appctx *appctx)
        }
 
   end:
-       if (!(res->flags & CF_SHUTR) && appctx->st0 == HTX_CACHE_END) {
-               res->flags |= CF_READ_EVENT;
+       if (!(res->flags & CF_SHUTR) && appctx->st0 == HTX_CACHE_END)
                sc_shutr(sc);
-       }
 
   out:
        total = res_htx->data - total;
index b683652a303792014c5eec4481715c9d91ee2f3c..7058d7b0e1718dc209915e0ed558f5c1124ec848 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1183,7 +1183,6 @@ static void cli_io_handler(struct appctx *appctx)
                 * on the response buffer.
                 */
                sc_shutr(sc);
-               res->flags |= CF_READ_EVENT;
        }
 
  out:
index 057935ab7937892b07d7bbaebe229d07568aa1ec..9b09dfb053b2355b43835e24cbb6496bae5144de 100644 (file)
--- a/src/dns.c
+++ b/src/dns.c
@@ -765,7 +765,6 @@ read:
 close:
        sc_shutw(sc);
        sc_shutr(sc);
-       sc_ic(sc)->flags |= CF_READ_EVENT;
 }
 
 void dns_queries_flush(struct dns_session *ds)
index 1f6b3a9f38792881b7cb9f31dffff2caac5788ae..327614e44ecfa43fef0254df22b6743429435fbd 100644 (file)
@@ -1303,7 +1303,6 @@ spoe_release_appctx(struct appctx *appctx)
 
                sc_shutw(sc);
                sc_shutr(sc);
-               sc_ic(sc)->flags |= CF_READ_EVENT;
        }
 
        /* Destroy the task attached to this applet */
@@ -2022,7 +2021,6 @@ spoe_handle_appctx(struct appctx *appctx)
 
                        sc_shutw(sc);
                        sc_shutr(sc);
-                       sc_ic(sc)->flags |= CF_READ_EVENT;
                        __fallthrough;
 
                case SPOE_APPCTX_ST_END:
index 1771d143c7512c21081d318f357d7814594af2b1..be3c1ac03063499e0add7c313b69933c0e63c250 100644 (file)
@@ -2003,7 +2003,6 @@ static void hlua_socket_handler(struct appctx *appctx)
        if (ctx->die) {
                sc_shutw(sc);
                sc_shutr(sc);
-               sc_ic(sc)->flags |= CF_READ_EVENT;
                notification_wake(&ctx->wake_on_read);
                notification_wake(&ctx->wake_on_write);
                stream_shutdown(__sc_strm(sc), SF_ERR_KILLED);
@@ -9426,7 +9425,6 @@ void hlua_applet_tcp_fct(struct appctx *ctx)
        struct hlua_tcp_ctx *tcp_ctx = ctx->svcctx;
        struct stconn *sc = appctx_sc(ctx);
        struct stream *strm = __sc_strm(sc);
-       struct channel *res = sc_ic(sc);
        struct act_rule *rule = ctx->rule;
        struct proxy *px = strm->be;
        struct hlua *hlua = tcp_ctx->hlua;
@@ -9450,7 +9448,6 @@ void hlua_applet_tcp_fct(struct appctx *ctx)
 
                /* eat the whole request */
                co_skip(sc_oc(sc), co_data(sc_oc(sc)));
-               res->flags |= CF_READ_EVENT;
                sc_shutr(sc);
                return;
 
@@ -9732,10 +9729,8 @@ void hlua_applet_http_fct(struct appctx *ctx)
 
   done:
        if (http_ctx->flags & APPLET_DONE) {
-               if (!(res->flags & CF_SHUTR)) {
-                       res->flags |= CF_READ_EVENT;
+               if (!(res->flags & CF_SHUTR))
                        sc_shutr(sc);
-               }
 
                /* eat the whole request */
                if (co_data(req)) {
index 04ead1f6bb5773dbd0015267cd36be0511049ef3..da9766ddd5da306164ed47c53e93ff44117bc208 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -3688,9 +3688,6 @@ cli_abort:
 close:
        sc_shutw(sc);
        sc_shutr(sc);
-
-       sc_ic(sc)->flags |= CF_READ_EVENT;
-
        return;
 }
 
index e3eb049a8791ba4bd1bd1b45f4b10efb6a3c52ad..89e3bc78227d4064ba494c59cde2027ccc93df7c 100644 (file)
@@ -3195,7 +3195,6 @@ send_msgs:
                                }
                                sc_shutw(sc);
                                sc_shutr(sc);
-                               sc_ic(sc)->flags |= CF_READ_EVENT;
                                goto out;
                        }
                }
index 9c1c4d41af96adbadcaa63f08b7d41defb92cb59..bd04ec885b86266d319b1af4191a7e70ceaf6a07 100644 (file)
@@ -443,7 +443,6 @@ static void sink_forward_io_handler(struct appctx *appctx)
 close:
        sc_shutw(sc);
        sc_shutr(sc);
-       sc_ic(sc)->flags |= CF_READ_EVENT;
 }
 
 /*
@@ -585,7 +584,6 @@ static void sink_forward_oc_io_handler(struct appctx *appctx)
 close:
        sc_shutw(sc);
        sc_shutr(sc);
-       sc_ic(sc)->flags |= CF_READ_EVENT;
 }
 
 void __sink_forward_session_deinit(struct sink_forward_target *sft)
index 4ee8e868a8cb72d88e71e51989c9cbb8796469bb..d9bb367f7d904b44a2683fe807c39837179294be 100644 (file)
@@ -4506,10 +4506,8 @@ static void http_stats_io_handler(struct appctx *appctx)
        }
 
        if (appctx->st0 == STAT_HTTP_END) {
-               if (!(res->flags & CF_SHUTR)) {
-                       res->flags |= CF_READ_EVENT;
+               if (!(res->flags & CF_SHUTR))
                        sc_shutr(sc);
-               }
 
                /* eat the whole request */
                if (co_data(req)) {
index 07b9767b73ff1c4524bb429272ca2916413bd6b6..e6b7d597dfd3ddb55f4aa5f9ed8b7ba449b85eff 100644 (file)
@@ -533,8 +533,8 @@ static void sc_app_shutr(struct stconn *sc)
        struct channel *ic = sc_ic(sc);
 
        if (ic->flags & CF_SHUTR)
-               return;
-       ic->flags |= CF_SHUTR;
+
+       ic->flags |= CF_SHUTR|CF_READ_EVENT;
        sc_ep_report_read_activity(sc);
        sc_ep_reset_rex(sc);
 
@@ -569,7 +569,7 @@ static void sc_app_shutw(struct stconn *sc)
        oc->flags &= ~CF_SHUTW_NOW;
        if (oc->flags & CF_SHUTW)
                return;
-       oc->flags |= CF_SHUTW;
+       oc->flags |= CF_SHUTW|CF_WRITE_EVENT;
        sc_ep_reset_wex(sc);
 
        if (tick_isset(sc->hcto)) {
@@ -676,7 +676,7 @@ static void sc_app_shutr_conn(struct stconn *sc)
 
        if (ic->flags & CF_SHUTR)
                return;
-       ic->flags |= CF_SHUTR;
+       ic->flags |= CF_SHUTR|CF_READ_EVENT;
        sc_ep_reset_rex(sc);
 
        if (!sc_state_in(sc->state, SC_SB_CON|SC_SB_RDY|SC_SB_EST))
@@ -710,7 +710,7 @@ static void sc_app_shutw_conn(struct stconn *sc)
        oc->flags &= ~CF_SHUTW_NOW;
        if (oc->flags & CF_SHUTW)
                return;
-       oc->flags |= CF_SHUTW;
+       oc->flags |= CF_SHUTW|CF_WRITE_EVENT;
        sc_ep_reset_wex(sc);
 
        if (tick_isset(sc->hcto)) {
@@ -898,7 +898,7 @@ static void sc_app_shutr_applet(struct stconn *sc)
 
        if (ic->flags & CF_SHUTR)
                return;
-       ic->flags |= CF_SHUTR;
+       ic->flags |= CF_SHUTR|CF_READ_EVENT;
        sc_ep_reset_rex(sc);
 
        /* Note: on shutr, we don't call the applet */
@@ -933,7 +933,7 @@ static void sc_app_shutw_applet(struct stconn *sc)
        oc->flags &= ~CF_SHUTW_NOW;
        if (oc->flags & CF_SHUTW)
                return;
-       oc->flags |= CF_SHUTW;
+       oc->flags |= CF_SHUTW|CF_WRITE_EVENT;
        sc_ep_reset_wex(sc);
 
        if (tick_isset(sc->hcto)) {
@@ -1240,7 +1240,7 @@ static void sc_conn_read0(struct stconn *sc)
 
        if (ic->flags & CF_SHUTR)
                return;
-       ic->flags |= CF_SHUTR;
+       ic->flags |= CF_SHUTR|CF_READ_EVENT;
        sc_ep_report_read_activity(sc);
        sc_ep_reset_rex(sc);
 
@@ -1589,7 +1589,6 @@ static int sc_conn_recv(struct stconn *sc)
                ret = 1;
        else if (sc_ep_test(sc, SE_FL_EOS)) {
                /* we received a shutdown */
-               ic->flags |= CF_READ_EVENT;
                if (ic->flags & CF_AUTO_CLOSE)
                        channel_shutw_now(ic);
                sc_conn_read0(sc);
@@ -1874,7 +1873,6 @@ static int sc_conn_process(struct stconn *sc)
         */
        if (sc_ep_test(sc, SE_FL_EOS) && !(ic->flags & CF_SHUTR)) {
                /* we received a shutdown */
-               ic->flags |= CF_READ_EVENT;
                if (ic->flags & CF_AUTO_CLOSE)
                        channel_shutw_now(ic);
                sc_conn_read0(sc);