about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2012-10-28 20:19:57 +0100
committerAlexander Barton <alex@barton.de>2012-10-29 11:33:49 +0100
commitfb924933765238808feb05fb7178402058026897 (patch)
tree08fe134aa1e4d3bbe1f2a64a600a7fd9a050d0c1
parenteb4f9eac0c35071838c9367f1204db0d0b98ad2e (diff)
downloadngircd-fb924933765238808feb05fb7178402058026897.tar.gz
ngircd-fb924933765238808feb05fb7178402058026897.zip
Make server reconnect time a little bit more random
Add randomly up to 15 seconds to the reconnect delay for outgoing server
links when the connection has been "short" and therefore the "ConnectRetry"
delay is being enforced.

This should make it even more unlikely that two servers deadlock each
other when both are trying to connect to the other one at the same time,
for example in test environments.
-rw-r--r--src/ngircd/conf.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c
index 6a7f6339..81525129 100644
--- a/src/ngircd/conf.c
+++ b/src/ngircd/conf.c
@@ -481,8 +481,12 @@ Conf_UnsetServer( CONN_ID Idx )
 				 * require the next attempt to be delayed. */
 				Conf_Server[i].lasttry =
 					t - Conf_ConnectRetry + RECONNECT_DELAY;
-			} else
-				Conf_Server[i].lasttry = t;
+			} else {
+				/* "Short" connection, enforce "ConnectRetry"
+				 * but randomize it a little bit: 15 seconds. */
+				Conf_Server[i].lasttry =
+					t + rand() / (RAND_MAX / 15);
+			}
 		}
 	}
 }