From 32e5a0f2815a549d5211a257bc7096ea6ef6faac Mon Sep 17 00:00:00 2001 From: Kevin Easton Date: Mon, 21 Jan 2019 17:01:20 +1100 Subject: [PATCH] Retry the initial server connection the correct number of times The previous code relied on server[i].retries being equal to one less than the number of connection attempts that had been made on entry to advance_server(), but this was false for the initial connection attempt. Change the code instead so that on entry to advance_server(), server[i].retries is always the number of previous connection attempts that have been made. This does the right thing for initial connection attempts since .retries starts at zero. --- Changelog | 3 +++ source/server.c | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Changelog b/Changelog index 5894e76..028a432 100644 --- a/Changelog +++ b/Changelog @@ -1,5 +1,8 @@ [Changes 1.2.2] +* Fix bug where the initial server connection was only retried one less than + MAX_SERVER_RECONNECT times. (caf) + * Improve error messages for SSL connection failures. (caf) * Correctly handle reconnection after failure of SSL connection setup. diff --git a/source/server.c b/source/server.c index 1f3792a..81e2ef6 100644 --- a/source/server.c +++ b/source/server.c @@ -322,7 +322,7 @@ int find_old_server(int old_server) return -1; } -int advance_server(int i) +static int advance_server(int i) { int server = i; @@ -331,10 +331,10 @@ int advance_server(int i) * try again or move to the next server. */ - server_list[i].retries++; if (server_list[i].retries >= get_int_var(MAX_SERVER_RECONNECT_VAR)) { server = next_server(i); + set_server_retries(server, 0); if (server != i) { @@ -346,7 +346,6 @@ int advance_server(int i) set_server_req_server(server, server_list[i].req_server); set_server_old_server(server, server_list[i].old_server); set_server_change_refnum(server, server_list[i].server_change_refnum); - set_server_retries(server, 0); #ifdef NON_BLOCKING_CONNECTS server_list[server].from_server = server_list[i].from_server; server_list[server].c_server = server_list[i].c_server; @@ -363,6 +362,7 @@ int advance_server(int i) #endif } } + server_list[server].retries++; if (!get_int_var(AUTO_RECONNECT_VAR) && (server_list[server].req_server != server || server_list[server].retries > 1)) {