Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/flb_pack.c
Original file line number Diff line number Diff line change
Expand Up @@ -1478,9 +1478,10 @@ char *flb_msgpack_to_json_str(size_t size, const msgpack_object *obj, int escape

while (1) {
ret = flb_msgpack_to_json(buf, size, obj, escape_unicode);
if (ret <= 0) {
if (ret < 0) {
/* buffer is small. retry.*/
size *= 2;
flb_info("failed to convert msgpack to json, retrying with new size=%zu", size);
tmp = flb_realloc(buf, size);
if (tmp) {
buf = tmp;
Expand All @@ -1491,6 +1492,12 @@ char *flb_msgpack_to_json_str(size_t size, const msgpack_object *obj, int escape
return NULL;
}
}
else if (ret == 0) {
/* nothing to pack */
flb_warn("unexpected result from flb_msgpack_to_json: 0");
flb_free(buf);
return NULL;
Comment on lines +1495 to +1499

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Stop retrying when msgpack buffer is too small

The loop used to treat any non‑positive return from flb_msgpack_to_json as “buffer too small” and double the buffer until the conversion succeeded. Now only < 0 retries, while a zero result drops into this branch, logs a warning and bails out. However flb_msgpack_to_json returns 0 (not a negative value) whenever the output buffer lacks space, so this change aborts instead of reallocating. Any call that passes a modest initial size will now fail for larger records where it previously succeeded. Consider restoring the retry when ret == 0 so the function still grows the buffer.

Useful? React with 👍 / 👎.

}
else {
break;
}
Expand Down