MINOR: cli: handle EOS/ERROR first
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 16 Jun 2025 14:29:07 +0000 (16:29 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Tue, 17 Jun 2025 06:04:42 +0000 (08:04 +0200)
It is not especially a bug fixed. But APPCTX_FL_EOS and APPCTX_FL_ERROR
flags must be handled first. These flags are set by the applet itself and
should mark the end of all processing. So there is not reason to get the
output buffer in first place.

This patch could be backported as far as 3.0.

(cherry picked from commit fb7665552668df368bbc85ef56beca11c356f53a)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 9a874dc54c3a6eb061f19d0a65e882d17d4b1a3e)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit a1246d92eeeb50f6b10349fb6848e9cead969c0e)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>

src/cli.c

index 7a3c1d2..0686463 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1062,17 +1062,18 @@ size_t cli_snd_buf(struct appctx *appctx, struct buffer *buf, size_t count, unsi
  */
 void cli_io_handler(struct appctx *appctx)
 {
-       if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC|APPCTX_FL_OUTBLK_FULL) ||
-           !appctx_get_buf(appctx, &appctx->outbuf)) {
-                applet_wont_consume(appctx);
-               goto out;
-       }
 
        if (unlikely(applet_fl_test(appctx, APPCTX_FL_EOS|APPCTX_FL_ERROR))) {
                appctx->st0 = CLI_ST_END;
                goto out;
        }
 
+       if (applet_fl_test(appctx, APPCTX_FL_OUTBLK_ALLOC|APPCTX_FL_OUTBLK_FULL) ||
+           !appctx_get_buf(appctx, &appctx->outbuf)) {
+                applet_wont_consume(appctx);
+               goto out;
+       }
+
        while (1) {
                if (appctx->st0 == CLI_ST_INIT) {
                        /* reset severity to default at init */