-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Dietwall fix msgpack to json #11083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Dietwall fix msgpack to json #11083
Conversation
WalkthroughThe change modifies error handling in the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| else if (ret == 0) { | ||
| /* nothing to pack */ | ||
| flb_warn("unexpected result from flb_msgpack_to_json: 0"); | ||
| flb_free(buf); | ||
| return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/flb_pack.c (2)
1481-1500: Retry logic change prevents infinite loops but may need refinement.The change from
ret <= 0toret < 0with explicitret == 0handling prevents infinite retry loops, which is good. However, this also means legitimate "buffer too small" cases (whereflb_msgpack_to_jsonreturns 0) no longer trigger retries.Consider these improvements:
Add a retry counter to prevent infinite loops while still allowing reasonable retries:
int retry_count = 0; int max_retries = 10; while (retry_count < max_retries) { ret = flb_msgpack_to_json(buf, size, obj, escape_unicode); if (ret < 0 || ret == 0) { size *= 2; retry_count++; // ... realloc logic } else { break; } } if (retry_count >= max_retries) { flb_warn("max retries reached in msgpack-to-json conversion"); flb_free(buf); return NULL; }Track progress by checking if any bytes were written between iterations to detect true failure vs. insufficient buffer.
The current approach is a reasonable first step given the PR acknowledges more work is needed for issue #11078.
Based on learnings: The PR objectives indicate this is incomplete work, so the current trade-off (safety over functionality) aligns with incremental improvement.
1484-1484: Consider enhancing the log message with return value context.The log message is helpful, but including the return value could aid debugging:
- flb_info("failed to convert msgpack to json, retrying with new size=%zu", size); + flb_info("failed to convert msgpack to json (ret=%d), retrying with new size=%zu", ret, size);This would help distinguish between different error scenarios in logs.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/flb_pack.c(2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: shadowshot-x
PR: fluent/fluent-bit#10825
File: plugins/out_s3/s3.c:1339-1344
Timestamp: 2025-09-04T12:35:22.872Z
Learning: In the Fluent Bit S3 plugin, the user prefers to maintain current retry_limit behavior without special handling for FLB_OUT_RETRY_UNLIMITED (-1), as there's no documentation indicating -1 should be used for infinite retries and consistency with current logic is preferred.
Learnt from: shadowshot-x
PR: fluent/fluent-bit#10825
File: plugins/out_s3/s3.c:3275-3282
Timestamp: 2025-09-04T12:35:36.904Z
Learning: The out_s3 plugin intentionally uses a simple numeric comparison for retry_limit (chunk->failures >= ctx->ins->retry_limit) rather than the standard Fluent Bit pattern that checks for FLB_OUT_RETRY_UNLIMITED (-1). The maintainer wants to keep this current behavior for consistency within the plugin.
🧬 Code graph analysis (1)
src/flb_pack.c (1)
include/fluent-bit/flb_mem.h (1)
flb_free(126-128)
|
7 tests failed. |
slightly better error handling on internal errors
first work for #11078
however, this error implies that more work is needed.
Enter
[N/A]in the box, if an item is not applicable to your change.Testing
Before we can approve your change; please submit the following in a comment:
If this is a change to packaging of containers or native binaries then please confirm it works for all targets.
ok-package-testlabel to test for all targets (requires maintainer to do).Documentation
Backporting
Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.
Summary by CodeRabbit
Release Notes