]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUG/MINOR: contrib/prometheus-exporter: Don't try to add empty data blocks
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 4 Jul 2019 08:03:28 +0000 (10:03 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 5 Jul 2019 12:26:14 +0000 (14:26 +0200)
When the response buffer is full and nothing more can be inserted, it is
important to not try to insert an empty data block. Otherwise, when the function
channel_add_input() is called, the flag CF_READ_PARTIAL is set on the response
channel while nothing was read and the stream is uselessly woken up. Finally, we
have loop while the response buffer is full.

This patch must be backported to 2.0.

contrib/prometheus-exporter/service-prometheus.c

index b57af9944e79308138ec27fc576cfc1786ee0235..2aafd4d87bfdb9ebc06a45d7600c306c010a0825 100644 (file)
@@ -1408,9 +1408,11 @@ static int promex_dump_global_metrics(struct appctx *appctx, struct htx *htx)
        }
 
   end:
-       if (!htx_add_data_atonce(htx, out))
-               return -1; /* Unexpected and unrecoverable error */
-       channel_add_input(chn, out.len);
+       if (out.len) {
+               if (!htx_add_data_atonce(htx, out))
+                       return -1; /* Unexpected and unrecoverable error */
+               channel_add_input(chn, out.len);
+       }
        return ret;
   full:
        ret = 0;
@@ -1586,9 +1588,11 @@ static int promex_dump_front_metrics(struct appctx *appctx, struct htx *htx)
        }
 
   end:
-       if (!htx_add_data_atonce(htx, out))
-               return -1; /* Unexpected and unrecoverable error */
-       channel_add_input(chn, out.len);
+       if (out.len) {
+               if (!htx_add_data_atonce(htx, out))
+                       return -1; /* Unexpected and unrecoverable error */
+               channel_add_input(chn, out.len);
+       }
        return ret;
   full:
        ret = 0;
@@ -1804,9 +1808,11 @@ static int promex_dump_back_metrics(struct appctx *appctx, struct htx *htx)
        }
 
   end:
-       if (!htx_add_data_atonce(htx, out))
-               return -1; /* Unexpected and unrecoverable error */
-       channel_add_input(chn, out.len);
+       if (out.len) {
+               if (!htx_add_data_atonce(htx, out))
+                       return -1; /* Unexpected and unrecoverable error */
+               channel_add_input(chn, out.len);
+       }
        return ret;
   full:
        ret = 0;
@@ -1998,9 +2004,11 @@ static int promex_dump_srv_metrics(struct appctx *appctx, struct htx *htx)
 
 
   end:
-       if (!htx_add_data_atonce(htx, out))
-               return -1; /* Unexpected and unrecoverable error */
-       channel_add_input(chn, out.len);
+       if (out.len) {
+               if (!htx_add_data_atonce(htx, out))
+                       return -1; /* Unexpected and unrecoverable error */
+               channel_add_input(chn, out.len);
+       }
        return ret;
   full:
        ret = 0;