]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[mod_mariadb] Fix reconnect during db failover/restart
authorNathan Neulinger <nneul@neulinger.org>
Mon, 23 Mar 2020 16:55:00 +0000 (11:55 -0500)
committerGitHub <noreply@github.com>
Mon, 23 Mar 2020 16:55:00 +0000 (20:55 +0400)
src/mod/databases/mod_mariadb/mod_mariadb.c

index cdd64ffb81d80e67d438503753c724227f8f2f43..7926ec0c3f52daa86a1565177396fa75408b66b2 100644 (file)
@@ -53,6 +53,8 @@ int mariadb_db_set_connection(MYSQL *mysql, enum enum_server_command command, co
        size_t length, my_bool skipp_check, void *opt_arg);
 my_bool mariadb_db_dsn_reconnect(MYSQL *mysql);
 
+my_bool reconnect = 1;
+
 #define DEFAULT_MARIADB_RETRIES 120
 
 #ifndef MIN
@@ -474,10 +476,13 @@ switch_status_t mariadb_handle_connect(mariadb_handle_t *handle)
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Connecting %s\n", handle->dsn);
        mysql_init(&handle->con);
 
-       // Enable non-blocking operation
-       // https://mariadb.com/kb/en/library/using-the-non-blocking-library/
+       /* Enable non-blocking operation */
+       /* https://mariadb.com/kb/en/library/using-the-non-blocking-library */
        mysql_options(&handle->con, MYSQL_OPT_NONBLOCK, 0);
 
+       /* Enable automatic reconnect with the mariadb_reconnect function, without this that function does not work */
+       mysql_options(&handle->con, MYSQL_OPT_RECONNECT, &reconnect);
+
        /* set timeouts to 300 microseconds */
        /*int default_timeout = 3;
        mysql_options(&handle->con, MYSQL_OPT_READ_TIMEOUT, &default_timeout);