fix: switch to less aggressive backoff algorithm
authorKyle Fuller <redacted>
Sat, 24 Sep 2022 12:02:54 +0000 (13:02 +0100)
committerKyle Fuller <redacted>
Sat, 24 Sep 2022 12:04:31 +0000 (13:04 +0100)
This results in retry delays of:

* 2 seconds
* 4 seconds
* 6 seconds
* 8 seconds
* 10 seconds

palaver.cpp
test/test_palaver.py

index a548df88416225633e06930db28ee0515e8bcd5f..f136bcfdc7b8ca092803085d263fd5e39e3650df 100644 (file)
@@ -10,7 +10,6 @@
 #define ZNC_PALAVER_VERSION "1.2.1"
 
 #include <algorithm>
-#include <cmath>
 
 #include <znc/Modules.h>
 #include <znc/User.h>
@@ -128,9 +127,9 @@ public:
        }
 
        unsigned int GetDelay(unsigned int uAttempts) {
-               double minimumBackoff = 1;
-               double maximumBackoff = 10;
-               return std::max(std::min(pow((double)uAttempts, 2), maximumBackoff), minimumBackoff);
+               unsigned int minimumBackoff = 1;
+               unsigned int maximumBackoff = 10;
+               return std::max(std::min(uAttempts * 2, maximumBackoff), minimumBackoff);
        }
 };
 
index 7266bc7241b9b9d3f2065a6bb9b70e02fff70cf1..d6994d10e8fc2be1998c0f7792b84966053f73ca 100644 (file)
@@ -320,7 +320,7 @@ async def test_receiving_notification_with_retry_on_rate_limit(znc):
     line = await reader.readline()
     assert line == b':*palaver!znc@znc.in PRIVMSG admin :Notification sent to 1 clients.\r\n'
 
-    await asyncio.sleep(1.2)
+    await asyncio.sleep(2.2)
     server.close()
     await server.wait_closed()
 
@@ -376,7 +376,7 @@ async def test_receiving_notification_with_retry_on_server_error(znc):
     line = await reader.readline()
     assert line == b':*palaver!znc@znc.in PRIVMSG admin :Notification sent to 1 clients.\r\n'
 
-    await asyncio.sleep(1.2)
+    await asyncio.sleep(2.2)
     server.close()
     await server.wait_closed()
 
@@ -433,7 +433,7 @@ async def test_receiving_notification_with_retry_on_disconnect(znc):
     line = await reader.readline()
     assert line == b':*palaver!znc@znc.in PRIVMSG admin :Notification sent to 1 clients.\r\n'
 
-    await asyncio.sleep(1.2)
+    await asyncio.sleep(2.2)
     server.close()
     await server.wait_closed()
 
git clone https://git.99rst.org/PROJECT