-
Notifications
You must be signed in to change notification settings - Fork 5k
fix:clientHbReq deserialize problem #34198
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
Conversation
Summary of ChangesHello @Pengrongkun, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a deserialization problem related to client heartbeat requests by enhancing the robustness and reliability of message processing. It introduces stricter validation for connection types, refines error handling to ensure proper resource release upon failure, and implements a length-prefixed serialization strategy for batch heartbeat requests. These changes collectively prevent malformed data from causing issues and ensure accurate parsing of batched requests, leading to a more stable system. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Pull request overview
This PR fixes a deserialization problem in clientHbReq by adding validation for connection types, improving error handling consistency, and implementing length-prefixed serialization/deserialization to prevent corrupted data from affecting subsequent heartbeat requests in a batch.
Key Changes:
- Added validation to reject invalid
connTypevalues before processing - Improved error handling by replacing direct returns with proper goto-based cleanup
- Implemented length-prefixed encoding/decoding for each heartbeat request within a batch to isolate parsing errors
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| // Verify that we read exactly the expected length | ||
| if (reqDecoder.pos != reqLen) { | ||
| terrno = TSDB_CODE_INVALID_MSG; |
Copilot
AI
Jan 7, 2026
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.
After deserializing each individual request with tDeserializeSClientHbReq, the memory allocated within that request needs to be freed if there's an error during the verification step (line 643-645). The function tDeserializeSClientHbReq allocates memory for pReq->query and pReq->info, but if reqDecoder.pos != reqLen check fails, these resources are not cleaned up before calling TAOS_CHECK_EXIT. This can cause a memory leak since tFreeClientHbReq is only called for items already added to the array.
| terrno = TSDB_CODE_INVALID_MSG; | |
| terrno = TSDB_CODE_INVALID_MSG; | |
| tFreeClientHbReq(&req); |
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.
Code Review
This pull request addresses a deserialization issue with batched SClientHbReq messages. The fix involves prefixing each serialized request with its length, and then using a sub-decoder during deserialization to handle each request individually. This is a robust solution that prevents errors from cascading in a batch. The changes also include several other improvements, such as adding validation for connType, fixing potential memory leaks by consistently using goto for error handling, and adding more detailed error logging. Overall, these changes significantly improve the robustness and maintainability of the code. I have one minor suggestion to improve code clarity.
| int32_t code = tSerializeSClientHbReq(&lenEncoder, pReq); | ||
| int32_t reqLen = lenEncoder.pos; | ||
| tEncoderClear(&lenEncoder); | ||
| if (code < 0) { | ||
| TAOS_CHECK_EXIT(code); | ||
| } |
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.
The local variable code shadows the function-scoped variable of the same name. This can be confusing and lead to subtle bugs. It's better to use a different name for the local variable to improve clarity and avoid potential issues.
int32_t ret = tSerializeSClientHbReq(&lenEncoder, pReq);
int32_t reqLen = lenEncoder.pos;
tEncoderClear(&lenEncoder);
if (ret < 0) {
TAOS_CHECK_EXIT(ret);
}
Description
Issue(s)
Checklist
Please check the items in the checklist if applicable.