Skip to content

fix: clearing user_ip in taos_options_connection does not take effect#33229

Merged
guanshengliang merged 8 commits into3.3.6from
fix/TD-38266-336
Oct 13, 2025
Merged

fix: clearing user_ip in taos_options_connection does not take effect#33229
guanshengliang merged 8 commits into3.3.6from
fix/TD-38266-336

Conversation

@yihaoDeng
Copy link
Copy Markdown
Contributor

Description

Please briefly describe the code changes in this pull request.

Checklist

Please check the items in the checklist if applicable.

  • Is the user manual updated?
  • Are the test cases passed and automated?
  • Is there no significant decrease in test coverage?

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @yihaoDeng, 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 an issue related to the handling and verification of user-provided IP addresses through the 'TSDB_OPTION_CONNECTION_USER_IP' connection option. It introduces a dedicated field for storing this user IP, updates the internal logic for setting and retrieving it, and enhances the test suite to thoroughly validate its functionality. The changes ensure that user-specified IP addresses are correctly managed and reflected in the system's connection information.

Highlights

  • Enhanced User IP Handling: Introduced a dedicated 'userDualIp' field within the 'SConnObj' structure to improve the storage and retrieval of user-provided IP addresses, separating it from the connection's actual address.
  • Updated Connection Option Example: The 'connect_example.c' file was modified to correctly demonstrate setting the 'TSDB_OPTION_CONNECTION_USER_IP' option and removed a redundant test block, simplifying the example.
  • Improved User IP Verification Tests: A new test utility 'checkUserIp' was added to 'connectOptionsTest.cpp' to query the 'performance_schema.perf_connections' table and verify the presence of the user-configured IP, ensuring the 'TSDB_OPTION_CONNECTION_USER_IP' option functions as expected.
  • Refactored IP Setting Logic: The internal 'setUserInfoIpToConn' function was updated to utilize the new 'userDualIp' field for storing user IP information, and an 'emptyIpRange' check was removed, streamlining the IP assignment process.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 appears to fix an issue related to setting a user-defined IP for a connection, including adding support for dual-stack IPs. The changes include updates to a C example, C++ tests, and the server-side management node implementation. My review has found a critical issue in the C example that could lead to a crash, along with several medium-severity issues related to code clarity, best practices, and maintainability in the example, test, and server code. Please review the detailed comments for suggestions on how to address these points.

TAOS *taos = taos_connect(host, user, passwd, db, port);
taos_options_connection(taos, TSDB_OPTION_CONNECTION_USER_IP, "localhost");

code = taos_options_connection(taos, TSDB_OPTION_CONNECTION_USER_IP, "192.168.1.1");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The taos handle is used here without being checked for NULL after the call to taos_connect on line 17. If taos_connect fails and returns NULL, this will lead to a segmentation fault. It is critical to add a NULL check immediately after the connection is established.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The header taos.h is already included on line 9. This inclusion is redundant and can be confusing. Please remove this line.

TAOS *taos = taos_connect(host, user, passwd, db, port);
taos_options_connection(taos, TSDB_OPTION_CONNECTION_USER_IP, "localhost");

code = taos_options_connection(taos, TSDB_OPTION_CONNECTION_USER_IP, "192.168.1.1");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The return value of taos_options_connection is assigned to code but it's never checked. Example code should demonstrate robust error handling. Please add a check for the return value to ensure the option was set successfully.


taos_free_result(pRes);

ASSERT(1);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This ASSERT(1) is redundant as it will always pass and serves no purpose. It can be safely removed to improve code clarity.

code = taos_options_connection(pConn, TSDB_OPTION_CONNECTION_USER_IP, "1292.168.0.2");
//ASSERT(code != 0); // add dual alter
CHECK_TAOS_OPTION_IP_ERROR(pConn, userIp, INADDR_NONE);
taosSsleep(6);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The magic number 6 is used for sleeping, likely to wait for a server-side update to propagate. Using magic numbers makes the code harder to understand and maintain. It would be better to define this as a named constant related to the underlying mechanism (e.g., HEARTBEAT_INTERVAL_SECONDS * 2) and use that constant here and in other similar places in this test file.

@guanshengliang guanshengliang merged commit da00480 into 3.3.6 Oct 13, 2025
17 of 20 checks passed
@guanshengliang guanshengliang changed the title Fix/TD-38266-336 fix: clearing user_ip in taos_options_connection does not take effect Oct 13, 2025
@guanshengliang guanshengliang deleted the fix/TD-38266-336 branch October 13, 2025 08:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants