MINOR: channel/applets: Stop to test CF_WRITE_ERROR flag if CF_SHUTW is enough
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 4 Jan 2023 13:11:10 +0000 (14:11 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 9 Jan 2023 17:41:08 +0000 (18:41 +0100)
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.

15 files changed:
include/haproxy/channel.h
src/activity.c
src/cli.c
src/debug.c
src/dns.c
src/map.c
src/mworker.c
src/proxy.c
src/ring.c
src/sink.c
src/ssl_ckch.c
src/ssl_crtlist.c
src/stconn.c
src/stick_table.c
src/stream.c

index 052ffee..8ef5b86 100644 (file)
@@ -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;
 
index f697358..5ee5fbb 100644 (file)
@@ -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);
index 23f77e5..ced990c 100644 (file)
--- 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);
index c9b912e..05c7a5c 100644 (file)
@@ -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) {
index a6e6af8..883c293 100644 (file)
--- 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 */
index 46125ad..9713041 100644 (file)
--- 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.
                 */
index 82fa2a2..8b3be19 100644 (file)
@@ -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;
 
 
index e53cc4f..a0e8c15 100644 (file)
@@ -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);
index 91157a9..22ac304 100644 (file)
@@ -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);
index 3d0fda2..862a1ae 100644 (file)
@@ -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 */
index f8e63ed..7d07cad 100644 (file)
@@ -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) {
index 9027d0e..e76fb9a 100644 (file)
@@ -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) {
index 7590423..ab11ee8 100644 (file)
@@ -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);
index b6f3ef1..09c7c74 100644 (file)
@@ -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);
index 8367c89..a4b428c 100644 (file)
@@ -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.
                 */