Add mysql-resolution_family to control IPv4/IPv6 hostname resolution#5554
Add mysql-resolution_family to control IPv4/IPv6 hostname resolution#5554
mysql-resolution_family to control IPv4/IPv6 hostname resolution#5554Conversation
Agent-Logs-Url: https://github.com/sysown/proxysql/sessions/7d0ebed6-886c-4e06-add5-d74b44eced4a Co-authored-by: renecannao <3645227+renecannao@users.noreply.github.com>
Agent-Logs-Url: https://github.com/sysown/proxysql/sessions/7d0ebed6-886c-4e06-add5-d74b44eced4a Co-authored-by: renecannao <3645227+renecannao@users.noreply.github.com>
mysql-resolution_family to control IPv4/IPv6 hostname resolution
When the DNS cache misses, the hostname is passed directly to mysql_real_connect which uses the MariaDB client library's own getaddrinfo with AF_UNSPEC. The mysql-resolution_family setting only applies to the DNS cache resolver thread, not this fallback path. Add a comment documenting this known limitation.
This reverts commit d61e59e.
There was a problem hiding this comment.
Pull request overview
Adds a new MySQL global variable (mysql-resolution_family) to make backend hostname resolution deterministic with respect to IPv4 vs IPv6 by mapping the configured value into getaddrinfo() hints in the MySQL DNS resolver thread, while keeping default behavior (system/AF_UNSPEC) unchanged.
Changes:
- Introduces
include/MySQL_Resolution.hwith validation, normalization, andAF_*mapping helpers. - Extends MySQL runtime variable storage with
resolution_familyand uses it inmonitor_dns_resolver_thread()to sethints.ai_family. - Adds a focused standalone unit test and wires it into the unit test build.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
include/MySQL_Resolution.h |
Header-only helpers for validating/normalizing the setting and mapping to AF_UNSPEC/AF_INET/AF_INET6. |
include/MySQL_Thread.h |
Adds resolution_family to MySQL thread variables struct. |
lib/MySQL_Thread.cpp |
Registers, defaults, exposes, validates, and persists resolution_family in MySQL runtime variables. |
lib/MySQL_Monitor.cpp |
Applies resolution_family to getaddrinfo() hints in the DNS resolver thread. |
lib/mysql_connection.cpp |
Documents the known limitation for DNS-cache-miss path using mysql_real_connect. |
test/tap/tests/unit/mysql_resolution_unit-t.cpp |
Unit coverage for validation/normalization/mapping behavior. |
test/tap/tests/unit/Makefile |
Adds the new unit test target and build rule. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lib/MySQL_Monitor.cpp
Outdated
| hints.ai_flags = AI_ADDRCONFIG; | ||
| char* resolution_family = GloMTH ? GloMTH->get_variable_string((char *)"resolution_family") : NULL; | ||
| hints.ai_family = mysql_resolution_family_to_ai_family(resolution_family); | ||
| if (resolution_family) { | ||
| free(resolution_family); | ||
| } |
There was a problem hiding this comment.
GloMTH->get_variable_string("resolution_family") is called without holding the MySQL threads handler lock. set_variable() updates string variables by free() + strdup(), and get_variable_string() does a strdup() of the underlying pointer without internal locking, so this read can race with a concurrent variable update and lead to use-after-free/crash. Acquire GloMTH->wrlock() (there is no rdlock) around reading resolution_family (and release it before getaddrinfo()), or otherwise fetch the configured family in a thread-safe/cached way.
Review: Thread storage variable missing for
|
Replace direct GloMTH->get_variable_string() call in monitor_dns_resolver_thread() with the proper mysql_thread___ thread-local variable pattern: - Add __thread char* mysql_thread___resolution_family in proxysql_structs.h - Add REFRESH_VARIABLE_CHAR(resolution_family) in refresh_variables() - Free the thread-local variable in MySQL_Thread destructor - Read mysql_thread___resolution_family directly in the monitor thread instead of taking a lock via get_variable_string()
|



ProxySQL currently defers backend hostname resolution entirely to the system resolver, which can cause
mysql_servers.hostnameentries to resolve to IPv4 or IPv6 unpredictably depending on host policy and DNS responses. This change adds a global MySQL setting to make address-family selection deterministic when needed, while preserving current behavior by default.New global variable
mysql-resolution_familysystem— use OS/default resolver behavior (AF_UNSPEC)ipv4— resolve only IPv4 addresses (AF_INET)ipv6— resolve only IPv6 addresses (AF_INET6)Runtime variable handling
resolution_familysystemDNS resolution path
mysql-resolution_familygetaddrinfo()hints.ai_familyAI_ADDRCONFIGbehaviorFocused unit coverage
AF_UNSPEC/AF_INET/AF_INET6Known limitations
mysql_real_connectwhich resolves it via the MariaDB client library using hardcodedAF_UNSPEC. Themysql-resolution_familysetting does not apply in this path. To ensure the setting is effective, the DNS cache must be enabled and populated (which is the default behavior when monitor is active). A future enhancement may address this by patching the client library.pgsql-resolution_familyvariable.Example usage