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);
}
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); }