[BUG] Flush buffers also where there are exactly 0 bytes left
I noticed it was possible to get truncated http/csv stats. Sometimes.
Usually the problem disappeared as fast as it appeared, but once it
happend that my http-stats page was truncated for about one hour.
It was quite weird as it happened independently for csv and http
output and it took me some time to track & fix this bug.
Both buffer_write & buffer_write_chunk used to return 0 in two
situations: is case of success or where there was exactly 0 bytes
left. The first one is intentional but I believe the second one
is not as it was not possible to distinguish between successful
write and unsuccessful one, which means that if the buffer was 100%
filled, it was never flushed and it was not possible to write
more data.
This patch fixes this problem.
diff --git a/src/dumpstats.c b/src/dumpstats.c
index a9fb84d..ddadddd 100644
--- a/src/dumpstats.c
+++ b/src/dumpstats.c
@@ -204,7 +204,7 @@
case DATA_ST_HEAD:
if (s->data_ctx.stats.flags & STAT_SHOW_STAT) {
print_csv_header(&msg, sizeof(trash));
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
}
@@ -240,7 +240,7 @@
global.maxconn,
actconn
);
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
}
@@ -422,7 +422,7 @@
} else {
print_csv_header(&msg, sizeof(trash));
}
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
s->data_state = DATA_ST_INFO;
@@ -532,7 +532,7 @@
""
);
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
}
@@ -561,7 +561,7 @@
case DATA_ST_END:
if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
chunk_printf(&msg, sizeof(trash), "</body></html>\n");
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
}
@@ -656,7 +656,7 @@
"</tr>",
px->id);
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
}
@@ -725,7 +725,7 @@
relative_pid, px->uuid, STATS_TYPE_FE);
}
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
}
@@ -942,7 +942,7 @@
/* type, then EOL */
chunk_printf(&msg, sizeof(trash), "%d,\n", STATS_TYPE_SV);
}
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
} /* for sv */
@@ -1039,7 +1039,7 @@
relative_pid, px->uuid,
px->cum_lbconn, STATS_TYPE_BE);
}
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
}
@@ -1050,7 +1050,7 @@
if (!(s->data_ctx.stats.flags & STAT_FMT_CSV)) {
chunk_printf(&msg, sizeof(trash), "</table><p>\n");
- if (buffer_write_chunk(rep, &msg) != 0)
+ if (buffer_write_chunk(rep, &msg) >= 0)
return 0;
}