And here is a more conservative patch for MySQL client retries.

It closes the server connection after every error, and it delays
making a new server connection only after specific errors.

Closing the connection eliminates the possibility that the client
becomes stuck.

        Wietse
20230417

        Cleanup: in the MySQL client, temporarily stay away from a
        server only if the last error was caused by a connection-level
        or protocol-level failure. File: global/dict_mysql.c.
        
diff -ur /var/tmp/postfix-3.9-20230416/src/global/dict_mysql.c 
./src/global/dict_mysql.c
--- /var/tmp/postfix-3.9-20230416/src/global/dict_mysql.c       2023-04-16 
16:44:39.000000000 -0400
+++ ./src/global/dict_mysql.c   2023-04-17 19:17:02.000000000 -0400
@@ -108,6 +108,7 @@
 /* Application-specific. */
 
 #include "dict_mysql.h"
+#include "mysql/errmsg.h"
 
 /* MySQL 8.x API change */
 
@@ -179,7 +180,7 @@
 static int plmysql_query(DICT_MYSQL *, const char *, VSTRING *, MYSQL_RES **);
 static void plmysql_dealloc(PLMYSQL *);
 static void plmysql_close_host(HOST *);
-static void plmysql_down_host(HOST *);
+static void plmysql_down_host(HOST *, int);
 static void plmysql_connect_single(DICT_MYSQL *, HOST *);
 static const char *dict_mysql_lookup(DICT *, const char *);
 DICT   *dict_mysql_open(const char *, int, int);
@@ -546,7 +547,16 @@
         * See what we got.
         */
        if (query_error) {
-           plmysql_down_host(host);
+           switch (mysql_errno(host->db)) {
+           case CR_COMMANDS_OUT_OF_SYNC:
+           case CR_SERVER_GONE_ERROR:
+           case CR_SERVER_LOST:
+               plmysql_down_host(host, RETRY_CONN_INTV);
+               break;
+           default:
+               plmysql_down_host(host, 0);
+               break;
+           }
            if (errno == 0)
                errno = ENOTSUP;
            if (first_result) {
@@ -609,7 +619,7 @@
     } else {
        msg_warn("connect to mysql server %s: %s",
                 host->hostname, mysql_error(host->db));
-       plmysql_down_host(host);
+       plmysql_down_host(host, RETRY_CONN_INTV);
     }
 }
 
@@ -625,11 +635,11 @@
  * plmysql_down_host - close a failed connection AND set a "stay away from
  * this host" timer
  */
-static void plmysql_down_host(HOST *host)
+static void plmysql_down_host(HOST *host, int delay)
 {
     mysql_close(host->db);
     host->db = 0;
-    host->ts = time((time_t *) 0) + RETRY_CONN_INTV;
+    host->ts = time((time_t *) 0) + delay;
     host->stat = STATFAIL;
     event_cancel_timer(dict_mysql_event, (void *) host);
 }
_______________________________________________
Postfix-users mailing list -- postfix-users@postfix.org
To unsubscribe send an email to postfix-users-le...@postfix.org

Reply via email to