From b08c5259eba461c4f88d6be24916d5f8add10298 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 20 Feb 2023 07:55:19 +0100 Subject: [PATCH] MINOR: stconn: Always report READ/WRITE event on shutr/shutw 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. --- addons/promex/service-prometheus.c | 2 -- src/backend.c | 7 ------- src/cache.c | 4 +--- src/cli.c | 1 - src/dns.c | 1 - src/flt_spoe.c | 2 -- src/hlua.c | 7 +------ src/log.c | 3 --- src/peers.c | 1 - src/sink.c | 2 -- src/stats.c | 4 +--- src/stconn.c | 18 ++++++++---------- 12 files changed, 11 insertions(+), 41 deletions(-) diff --git a/addons/promex/service-prometheus.c b/addons/promex/service-prometheus.c index 724d24b28..e4cc469ee 100644 --- a/addons/promex/service-prometheus.c +++ b/addons/promex/service-prometheus.c @@ -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; diff --git a/src/backend.c b/src/backend.c index 5a35bcc99..d022627ad 100644 --- a/src/backend.c +++ b/src/backend.c @@ -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) diff --git a/src/cache.c b/src/cache.c index 9683c088a..ae57ce544 100644 --- a/src/cache.c +++ b/src/cache.c @@ -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; diff --git a/src/cli.c b/src/cli.c index b683652a3..7058d7b0e 100644 --- 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: diff --git a/src/dns.c b/src/dns.c index 057935ab7..9b09dfb05 100644 --- 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) diff --git a/src/flt_spoe.c b/src/flt_spoe.c index 1f6b3a9f3..327614e44 100644 --- a/src/flt_spoe.c +++ b/src/flt_spoe.c @@ -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: diff --git a/src/hlua.c b/src/hlua.c index 1771d143c..be3c1ac03 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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)) { diff --git a/src/log.c b/src/log.c index 04ead1f6b..da9766ddd 100644 --- 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; } diff --git a/src/peers.c b/src/peers.c index e3eb049a8..89e3bc782 100644 --- a/src/peers.c +++ b/src/peers.c @@ -3195,7 +3195,6 @@ send_msgs: } sc_shutw(sc); sc_shutr(sc); - sc_ic(sc)->flags |= CF_READ_EVENT; goto out; } } diff --git a/src/sink.c b/src/sink.c index 9c1c4d41a..bd04ec885 100644 --- a/src/sink.c +++ b/src/sink.c @@ -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) diff --git a/src/stats.c b/src/stats.c index 4ee8e868a..d9bb367f7 100644 --- a/src/stats.c +++ b/src/stats.c @@ -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)) { diff --git a/src/stconn.c b/src/stconn.c index 07b9767b7..e6b7d597d 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -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);