From: Christopher Faulet Date: Wed, 4 Jan 2023 13:11:10 +0000 (+0100) Subject: MINOR: channel/applets: Stop to test CF_WRITE_ERROR flag if CF_SHUTW is enough X-Git-Tag: v2.8-dev2~70 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=da89e9b95b6c9e62cbdea2586c6ae2ddee96c4e4;p=thirdparty%2Fhaproxy.git MINOR: channel/applets: Stop to test CF_WRITE_ERROR flag if CF_SHUTW is enough In applets, we stop processing when a write error (CF_WRITE_ERROR) or a shutdown for writes (CF_SHUTW) is detected. However, any write error leads to an immediate shutdown for writes. Thus, it is enough to only test if CF_SHUTW is set. --- diff --git a/include/haproxy/channel.h b/include/haproxy/channel.h index 052ffee15a..8ef5b863d5 100644 --- a/include/haproxy/channel.h +++ b/include/haproxy/channel.h @@ -534,7 +534,7 @@ static inline void channel_check_timeouts(struct channel *chn) unlikely(tick_is_expired(chn->rex, now_ms))) chn->flags |= CF_READ_TIMEOUT; - if (likely(!(chn->flags & (CF_SHUTW|CF_WRITE_TIMEOUT|CF_WRITE_EVENT|CF_WRITE_ERROR))) && + if (likely(!(chn->flags & (CF_SHUTW|CF_WRITE_TIMEOUT|CF_WRITE_EVENT))) && unlikely(tick_is_expired(chn->wex, now_ms))) chn->flags |= CF_WRITE_TIMEOUT; diff --git a/src/activity.c b/src/activity.c index f697358a6c..5ee5fbb10e 100644 --- a/src/activity.c +++ b/src/activity.c @@ -624,7 +624,7 @@ static int cli_io_handler_show_profiling(struct appctx *appctx) int max_lines; int i, j, max; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) return 1; chunk_reset(&trash); @@ -887,7 +887,7 @@ static int cli_io_handler_show_tasks(struct appctx *appctx) int thr, queue; int i, max; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) return 1; /* It's not possible to scan queues in small chunks and yield in the @@ -1027,7 +1027,7 @@ static int cli_io_handler_show_activity(struct appctx *appctx) struct timeval up; int thr; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) return 1; chunk_reset(&trash); diff --git a/src/cli.c b/src/cli.c index 23f77e50cb..ced990cceb 100644 --- a/src/cli.c +++ b/src/cli.c @@ -1227,7 +1227,7 @@ static int cli_io_handler_show_env(struct appctx *appctx) struct stconn *sc = appctx_sc(appctx); char **var = ctx->var; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) return 1; chunk_reset(&trash); @@ -1264,7 +1264,7 @@ static int cli_io_handler_show_fd(struct appctx *appctx) int fd = fdctx->fd; int ret = 1; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) goto end; chunk_reset(&trash); diff --git a/src/debug.c b/src/debug.c index c9b912e98c..05c7a5cf96 100644 --- a/src/debug.c +++ b/src/debug.c @@ -313,7 +313,7 @@ static int cli_io_handler_show_threads(struct appctx *appctx) struct stconn *sc = appctx_sc(appctx); int thr; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) return 1; if (appctx->st0) @@ -1096,7 +1096,7 @@ static int debug_iohandler_fd(struct appctx *appctx) int ret = 1; int i, fd; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) goto end; chunk_reset(&trash); @@ -1303,7 +1303,7 @@ static int debug_iohandler_memstats(struct appctx *appctx) const char *pfx = ctx->match; int ret = 1; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) goto end; if (!ctx->width) { diff --git a/src/dns.c b/src/dns.c index a6e6af8bbd..883c293d4a 100644 --- a/src/dns.c +++ b/src/dns.c @@ -459,8 +459,7 @@ static void dns_session_io_handler(struct appctx *appctx) if (ds->shutdown) goto close; - /* an error was detected */ - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) goto close; /* con closed by server side, we will skip data write and drain data from channel */ diff --git a/src/map.c b/src/map.c index 46125ad9b3..9713041572 100644 --- a/src/map.c +++ b/src/map.c @@ -348,7 +348,7 @@ static int cli_io_handler_pat_list(struct appctx *appctx) struct stconn *sc = appctx_sc(appctx); struct pat_ref_elt *elt; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) { /* If we're forced to shut down, we might have to remove our * reference to the last ref_elt being dumped. */ diff --git a/src/mworker.c b/src/mworker.c index 82fa2a2a88..8b3be1916d 100644 --- a/src/mworker.c +++ b/src/mworker.c @@ -534,7 +534,7 @@ static int cli_io_handler_show_proc(struct appctx *appctx) char *uptime = NULL; char *reloadtxt = NULL; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) return 1; chunk_reset(&trash); @@ -669,7 +669,7 @@ static int cli_io_handler_show_loadstatus(struct appctx *appctx) if (!cli_has_level(appctx, ACCESS_LVL_OPER)) return 1; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) return 1; diff --git a/src/proxy.c b/src/proxy.c index e53cc4f72d..a0e8c15236 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -3189,7 +3189,7 @@ static int cli_io_handler_show_errors(struct appctx *appctx) struct stconn *sc = appctx_sc(appctx); extern const char *monthname[12]; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) return 1; chunk_reset(&trash); diff --git a/src/ring.c b/src/ring.c index 91157a90b3..22ac304750 100644 --- a/src/ring.c +++ b/src/ring.c @@ -347,7 +347,7 @@ int cli_io_handler_show_ring(struct appctx *appctx) size_t len, cnt; int ret; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) return 1; HA_RWLOCK_WRLOCK(LOGSRV_LOCK, &ring->lock); diff --git a/src/sink.c b/src/sink.c index 3d0fda2234..862a1ae322 100644 --- a/src/sink.c +++ b/src/sink.c @@ -330,8 +330,7 @@ static void sink_forward_io_handler(struct appctx *appctx) /* rto should not change but it seems the case */ sc_oc(sc)->rto = TICK_ETERNITY; - /* an error was detected */ - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) goto close; /* con closed by server side */ @@ -480,7 +479,7 @@ static void sink_forward_oc_io_handler(struct appctx *appctx) sc_oc(sc)->rto = TICK_ETERNITY; /* an error was detected */ - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) goto close; /* con closed by server side */ diff --git a/src/ssl_ckch.c b/src/ssl_ckch.c index f8e63edc33..7d07cad71b 100644 --- a/src/ssl_ckch.c +++ b/src/ssl_ckch.c @@ -2148,7 +2148,7 @@ static int cli_io_handler_commit_cert(struct appctx *appctx) struct ckch_store *old_ckchs, *new_ckchs = NULL; struct ckch_inst *ckchi; - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) goto end; while (1) { diff --git a/src/ssl_crtlist.c b/src/ssl_crtlist.c index 9027d0eba1..e76fb9a112 100644 --- a/src/ssl_crtlist.c +++ b/src/ssl_crtlist.c @@ -1098,7 +1098,7 @@ static int cli_io_handler_add_crtlist(struct appctx *appctx) /* for each bind_conf which use the crt-list, a new ckch_inst must be * created. */ - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) goto end; switch (ctx->state) { diff --git a/src/stconn.c b/src/stconn.c index 75904238d2..ab11ee8a27 100644 --- a/src/stconn.c +++ b/src/stconn.c @@ -850,7 +850,7 @@ static void sc_app_chk_snd_conn(struct stconn *sc) /* in case of special condition (error, shutdown, end of write...), we * have to notify the task. */ - if (likely((oc->flags & (CF_WRITE_EVENT|CF_WRITE_ERROR|CF_SHUTW)) || + if (likely((oc->flags & (CF_WRITE_EVENT|CF_SHUTW)) || ((oc->flags & CF_WAKE_WRITE) && ((channel_is_empty(oc) && !oc->to_forward) || !sc_state_in(sc->state, SC_SB_EST))))) { @@ -1127,7 +1127,7 @@ static void sc_notify(struct stconn *sc) /* update OC timeouts and wake the other side up if it's waiting for room */ if (oc->flags & (CF_WRITE_EVENT|CF_WRITE_ERROR)) { - if ((oc->flags & (CF_SHUTW|CF_WRITE_EVENT)) == CF_WRITE_EVENT && + if (!(oc->flags & CF_WRITE_ERROR) && !channel_is_empty(oc)) if (tick_isset(oc->wex)) oc->wex = tick_add_ifset(now_ms, oc->wto); diff --git a/src/stick_table.c b/src/stick_table.c index b6f3ef1e5d..09c7c74316 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -5022,7 +5022,7 @@ static int cli_io_handler_table(struct appctx *appctx) * data though. */ - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) { /* in case of abort, remove any refcount we might have set on an entry */ if (ctx->state == STATE_DUMP) { stksess_kill_if_expired(ctx->t, ctx->entry, 1); diff --git a/src/stream.c b/src/stream.c index 8367c89121..a4b428cd82 100644 --- a/src/stream.c +++ b/src/stream.c @@ -1782,7 +1782,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state) */ if (!((req->flags | res->flags) & (CF_SHUTR|CF_READ_EVENT|CF_READ_TIMEOUT|CF_SHUTW| - CF_WRITE_EVENT|CF_WRITE_ERROR|CF_WRITE_TIMEOUT)) && + CF_WRITE_EVENT|CF_WRITE_TIMEOUT)) && !(s->flags & SF_CONN_EXP) && !((sc_ep_get(scf) | scb->flags) & SE_FL_ERROR) && ((s->pending_events & TASK_WOKEN_ANY) == TASK_WOKEN_TIMER)) { @@ -3626,7 +3626,7 @@ static int cli_io_handler_dump_sess(struct appctx *appctx) goto done; } - if (unlikely(sc_ic(sc)->flags & (CF_WRITE_ERROR|CF_SHUTW))) { + if (unlikely(sc_ic(sc)->flags & CF_SHUTW)) { /* If we're forced to shut down, we might have to remove our * reference to the last stream being dumped. */