File tree Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Expand file tree Collapse file tree 1 file changed +24
-3
lines changed Original file line number Diff line number Diff line change @@ -1101,6 +1101,7 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
1101
1101
// Connect loop
1102
1102
{
1103
1103
bool connected = false ;
1104
+ std::random_device generator;
1104
1105
1105
1106
while (!host_list.empty () && !connected)
1106
1107
{
@@ -1120,7 +1121,7 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
1120
1121
1121
1122
while (!weights.empty () && !connected)
1122
1123
{
1123
- std::random_device generator;
1124
+
1124
1125
std::discrete_distribution<int > distribution (
1125
1126
weights.begin (), weights.end ());
1126
1127
@@ -1145,8 +1146,28 @@ void MySQL_Connection::init(ConnectOptionsMap & properties)
1145
1146
connected = true ;
1146
1147
break ;
1147
1148
}
1148
- catch (sql::SQLException&)
1149
- {}
1149
+ catch (sql::SQLException& e)
1150
+ {
1151
+ switch (e.getErrorCode ())
1152
+ {
1153
+ case ER_CON_COUNT_ERROR:
1154
+ case CR_SOCKET_CREATE_ERROR:
1155
+ case CR_CONNECTION_ERROR:
1156
+ case CR_CONN_HOST_ERROR:
1157
+ case CR_IPSOCK_ERROR:
1158
+ case CR_UNKNOWN_HOST:
1159
+ // On Network errors, continue
1160
+ break ;
1161
+ default :
1162
+ // If SQLSTATE not 08xxx, which is used for network errors
1163
+ if (e.getSQLState ().compare (0 ,2 , " 08" ) != 0 )
1164
+ {
1165
+ // Re-throw error and do not try another host
1166
+ throw ;
1167
+ }
1168
+ }
1169
+
1170
+ }
1150
1171
1151
1172
same_prio.erase (el);
1152
1173
weights.erase (weight_el);
You can’t perform that action at this time.
0 commit comments