Bug #120322 IPv6 detection is insufficient when IPv6 is disabled via sysctl
Description:
When `bind-address=*` (default), MySQL incorrectly detects IPv6 as available on Linux systems where IPv6 is disabled via `sysctl net.ipv6.conf.all.disable_ipv6=1`. The error log shows `IPv6 is available.`, but clients cannot connect via `::1`.
How to repeat:
1. Disable IPv6 via sysctl:
```bash
sysctl -w net.ipv6.conf.all.disable_ipv6=1
sysctl -w net.ipv6.conf.default.disable_ipv6=1
sysctl -w net.ipv6.conf.lo.disable_ipv6=1
```
2. Start MySQL with default `bind-address=*`.
3. Check the error log — it incorrectly shows:
```
[Note] [MY-010264] IPv6 is available.
```
4. Attempt to connect via IPv6:
```bash
mysql -h ::1 -P 3306 -u root
ERROR 2003 (HY000): Can't connect to MySQL server on '::1:3306' (99)
```
Connection fails — IPv6 is not actually functional.
## Expected Result
MySQL should detect that IPv6 is disabled, log `IPv6 is not available.`, and fall back to binding on `0.0.0.0` (IPv4-only).
## Actual Result
MySQL reports `IPv6 is available` and binds to `::` (dual-stack), but IPv6 connections fail.
## Root Cause
The detection code in `sql/conn_handler/socket_connection.cc` only checks whether `socket(AF_INET6, SOCK_STREAM, 0)` succeeds:
```cpp
const MYSQL_SOCKET s = mysql_socket_socket(0, AF_INET6, SOCK_STREAM, 0);
ipv6_available = mysql_socket_getfd(s) != INVALID_SOCKET;
if (ipv6_available) mysql_socket_close(s);
```
`sysctl disable_ipv6=1` disables IPv6 address assignment and routing but does **not** unload the kernel module, so `socket(AF_INET6)` still succeeds. An additional `bind()` check is needed to verify the IPv6 stack is actually functional.
Suggested fix:
After `socket(AF_INET6)` succeeds, attempt `bind([::]:0)` to verify the stack is usable. See attached patch.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.040 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.