Bug #8938 libmysql should loop through all hosts returned by getaddrinfo
Description:
I like OpenLDAP's behaviour of looping through all the hosts returned by getaddrinfo(), attempting to connect to each until a responsive server is found. This would make a fault-tolerant MySQL client trivial to write.
Issues:
1: if the connection timeout is applied per server, the client may block for a lot longer than expected
2: Aside from communications problems, what errors should cause the client to try the next server? Access denied, unknown database, ... ?
How to repeat:
Feature request.
Suggested fix:
Without concern for errors or portability:
struct addrinfo *addr, *addrlist;
struct addrinfo hints = {0, PF_UNSPEC, SOCK_STREAM,
0, 0, 0, 0, 0};
int gai_result = getaddrinfo(host, 0, &hints, &addrlist);
if (gai_result) {
Unknown host.
}
for (addr = addrlist; addr; addr = addr->ai_next) {
#define IPNAMELEN 20
char ipnamebuff[IPNAMELEN];
const char *ipname = inet_ntop(((struct sockaddr_in *)addr->ai_addr)->sin_family,
(void *)&((struct sockaddr_in *)addr->ai_addr)->sin_addr,
ipnamebuff, IPNAMELEN-1);
mysql_real_connect(mysql, ipname, user, pass, database, 0, 0, flags);
}
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.048 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.
Description: I like OpenLDAP's behaviour of looping through all the hosts returned by getaddrinfo(), attempting to connect to each until a responsive server is found. This would make a fault-tolerant MySQL client trivial to write. Issues: 1: if the connection timeout is applied per server, the client may block for a lot longer than expected 2: Aside from communications problems, what errors should cause the client to try the next server? Access denied, unknown database, ... ? How to repeat: Feature request. Suggested fix: Without concern for errors or portability: struct addrinfo *addr, *addrlist; struct addrinfo hints = {0, PF_UNSPEC, SOCK_STREAM, 0, 0, 0, 0, 0}; int gai_result = getaddrinfo(host, 0, &hints, &addrlist); if (gai_result) { Unknown host. } for (addr = addrlist; addr; addr = addr->ai_next) { #define IPNAMELEN 20 char ipnamebuff[IPNAMELEN]; const char *ipname = inet_ntop(((struct sockaddr_in *)addr->ai_addr)->sin_family, (void *)&((struct sockaddr_in *)addr->ai_addr)->sin_addr, ipnamebuff, IPNAMELEN-1); mysql_real_connect(mysql, ipname, user, pass, database, 0, 0, flags); }