Index: res/res_config_mysql.c =================================================================== --- res/res_config_mysql.c (revision 952) +++ res/res_config_mysql.c (working copy) @@ -1456,6 +1456,7 @@ ast_log(LOG_ERROR, "MySQL RealTime: Failed to connect database server %s on %s (err %d). Check debug for more info.\n", conn->name, !ast_strlen_zero(conn->host) ? conn->host : conn->sock, mysql_errno(&conn->handle)); ast_debug(1, "MySQL RealTime: Cannot Connect (%d): %s\n", mysql_errno(&conn->handle), mysql_error(&conn->handle)); conn->connected = 0; + conn->connect_time = 0; return 0; } } else { @@ -1463,13 +1464,16 @@ * So the postman pings twice. */ if (mysql_ping(&conn->handle) != 0 && (usleep(1) + 2 > 0) && mysql_ping(&conn->handle) != 0) { conn->connected = 0; + conn->connect_time = 0; ast_log(LOG_ERROR, "MySQL RealTime: Ping failed (%d). Trying an explicit reconnect.\n", mysql_errno(&conn->handle)); ast_debug(1, "MySQL RealTime: Server Error (%d): %s\n", mysql_errno(&conn->handle), mysql_error(&conn->handle)); goto reconnect_tryagain; } - conn->connected = 1; - conn->connect_time = time(NULL); + if (!conn->connected) { + conn->connected = 1; + conn->connect_time = time(NULL); + } if (mysql_select_db(&conn->handle, conn->name) != 0) { ast_log(LOG_WARNING, "MySQL RealTime: Unable to select database: %s. Still Connected (%u) - %s.\n", conn->name, mysql_errno(&conn->handle), mysql_error(&conn->handle)); @@ -1553,7 +1557,7 @@ AST_LIST_TRAVERSE(&cur->columns, col, list) { ast_cli(a->fd, "%-20.20s %-20.20s %3d\n", col->name, col->type, col->len); } - ast_mutex_unlock(&cur->lock); + release_table(cur); } else { ast_cli(a->fd, "No such table '%s'\n", a->argv[3]); }