Skip to content

Commit 357d676

Browse files
committed
fix(in_kubernetes_events): always consume entire payload to avoid duplicates
Critical fix: Always mark the entire HTTP payload as consumed, not just parsed lines. Otherwise the HTTP layer keeps the trailing fragment and we get duplicates when prepending chunk_buffer on the next call. This was causing 'bad formed JSON' errors in production because fragments were duplicated at chunk boundaries. Signed-off-by: Jesse Awan <jesse.awan@sap.com>
1 parent a6bf771 commit 357d676

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

plugins/in_kubernetes_events/kubernetes_events.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,6 @@ static int process_http_chunk(struct k8s_events* ctx, struct flb_http_client *c,
796796
if (ret == 0) {
797797
/* Successfully parsed JSON */
798798
flb_plg_debug(ctx->ins, "successfully parsed JSON event (%zu bytes)", token_size);
799-
if (!working_buffer) {
800-
*bytes_consumed += token_size + 1;
801-
}
802799
ret = process_watched_event(ctx, buf_data, buf_size);
803800
flb_free(buf_data);
804801
buf_data = NULL;
@@ -847,12 +844,12 @@ static int process_http_chunk(struct k8s_events* ctx, struct flb_http_client *c,
847844
}
848845

849846
/*
850-
* Mark bytes consumed from the current HTTP chunk.
851-
* If we used working_buffer, all original payload bytes are consumed.
847+
* At this point we've either parsed all complete lines and/or buffered
848+
* any remaining tail into ctx->chunk_buffer, so we no longer need any
849+
* bytes from this HTTP payload. Tell the HTTP client that the whole
850+
* payload has been consumed to avoid duplicates.
852851
*/
853-
if (working_buffer) {
854-
*bytes_consumed = c->resp.payload_size;
855-
}
852+
*bytes_consumed = c->resp.payload_size;
856853

857854
if (working_buffer) {
858855
flb_sds_destroy(working_buffer);

0 commit comments

Comments
 (0)