summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2020-04-14 17:20:27 +0200
committerJean-Sébastien Pédron <jean-sebastien@rabbitmq.com>2020-04-20 15:13:44 +0200
commitcf90ad2f782922350b0986b419fd9487203d2cfd (patch)
treead4dfab2c33d3d7fdfcf7b199a68862bce935815 /src
parente73791a140e97fb7356c5fb893b865937a37e2c6 (diff)
downloadrabbitmq-server-git-cf90ad2f782922350b0986b419fd9487203d2cfd.tar.gz
rabbit_feature_flags: Improve timeout computation in `mark_as_enabled_remotely()`
The rounded value of `(timer:now_diff(T1, T0) div 1000)` was often 0, leading to no decrease in timeout, i.e. the equivalent of an infinite loop. Now, the division happens after the substraction. Also, to avoid to much hammering, we sleep for one second between retries.
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_feature_flags.erl10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/rabbit_feature_flags.erl b/src/rabbit_feature_flags.erl
index cf2715a724..e0fb3a2fe1 100644
--- a/src/rabbit_feature_flags.erl
+++ b/src/rabbit_feature_flags.erl
@@ -1695,7 +1695,6 @@ mark_as_enabled_remotely(Nodes, FeatureName, IsEnabled, Timeout) ->
"nodes", [FeatureName, IsEnabled]),
ok;
_ ->
- T1 = erlang:timestamp(),
rabbit_log_feature_flags:error(
"Feature flags: failed to mark feature flag `~s` as enabled=~p "
"on the following nodes:", [FeatureName, IsEnabled]),
@@ -1704,12 +1703,17 @@ mark_as_enabled_remotely(Nodes, FeatureName, IsEnabled, Timeout) ->
[Node, Ret])
|| {Node, Ret} <- Rets,
Ret =/= ok],
- NewTimeout = Timeout - (timer:now_diff(T1, T0) div 1000),
+ Sleep = 1000,
+ T1 = erlang:timestamp(),
+ Duration = timer:now_diff(T1, T0),
+ NewTimeout = (Timeout * 1000 - Duration) div 1000 - Sleep,
if
NewTimeout > 0 ->
rabbit_log_feature_flags:debug(
"Feature flags: retrying with a timeout of ~b "
- "milliseconds", [NewTimeout]),
+ "ms after sleeping for ~b ms",
+ [NewTimeout, Sleep]),
+ timer:sleep(Sleep),
mark_as_enabled_remotely(FailedNodes,
FeatureName,
IsEnabled,