Le Jeudi 14 Janvier 2010 22:20:20, Cyril Bonté a écrit : > Please find the patch in attachment if you're interested.
Oops, 2 bugs were left in that version : 1. the 8 bytes for scramble buff are not needed when there's no password 2. sizeof(MYSQL40_HANDSHAKE_ACK) gives one more byte than required. Sorry for the previous patch. -- Cyril Bonté
--- haproxy-HEAD/src/checks.c 2010-01-14 11:41:31.000000000 +0100 +++ haproxy-ss-20100113-mysql/src/checks.c 2010-01-14 22:48:15.000000000 +0100 @@ -47,6 +47,14 @@ #include <proto/server.h> #include <proto/task.h> +const char MYSQL40_HANDSHAKE_ACK[] = + "\x07\x00\x00" /* packet length */ + "\x01" /* packet number */ + "\x00\x00" /* client capabilities */ + "\x00\x00\x01" /* max packet */ + "\x00" /* username (null terminated string) */ + "\x00"; /* filler (always 0x00) */ + const struct check_status check_statuses[HCHK_STATUS_SIZE] = { [HCHK_STATUS_UNKNOWN] = { SRV_CHK_UNKNOWN, "UNK", "Unknown" }, [HCHK_STATUS_INI] = { SRV_CHK_UNKNOWN, "INI", "Initializing" }, @@ -867,11 +875,19 @@ /* MySQL Error packet always begin with field_count = 0xff * contrary to OK Packet who always begin whith 0x00 */ if (trash[4] != '\xff') { + unsigned int packet_len; + + /* Sends immediatly an authentication packet. + * This will prevent haproxy to be blocked by the mysql server. + */ + send(fd, MYSQL40_HANDSHAKE_ACK, sizeof(MYSQL40_HANDSHAKE_ACK) - 1, MSG_DONTWAIT | MSG_NOSIGNAL); + /* We set the MySQL Version in description for information purpose * FIXME : it can be cool to use MySQL Version for other purpose, * like mark as down old MySQL server. */ - if (len > 51) { + packet_len = ((unsigned int) trash[0]) + (((unsigned int) trash[1]) << 8) + (((unsigned int) trash[2]) << 16); + if (len == packet_len + 4) { desc = ltrim(&trash[5], ' '); set_server_check_status(s, HCHK_STATUS_L7OKD, desc); }