From 4304560ce2b5a8caefbb9d36930b8d67a1145ed9 Mon Sep 17 00:00:00 2001 From: Alexander Kukushkin Date: Wed, 30 Jan 2019 12:38:24 +0100 Subject: [PATCH] Adjust read timeout for leader watch blocking query (#950) According to the Consul documentation the actual response timeout is increased by a small random amount of additional wait time added to the supplied maximum wait time to spread out the wake up time of any concurrent requests. It adds up to wait / 16 additional time to the maximum duration. In our case we will add wait/15 or 1 second depending on what is bigger. Fixes: https://github.com/zalando/patroni/issues/945 --- patroni/dcs/consul.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/patroni/dcs/consul.py b/patroni/dcs/consul.py index 950da93c..278262b0 100644 --- a/patroni/dcs/consul.py +++ b/patroni/dcs/consul.py @@ -102,7 +102,12 @@ class HTTPClient(object): params = {k: v for k, v in params} kwargs = {'retries': 0, 'preload_content': False, 'body': data} if method == 'get' and isinstance(params, dict) and 'index' in params: - kwargs['timeout'] = (float(params['wait'][:-1]) if 'wait' in params else 300) + 1 + timeout = float(params['wait'][:-1]) if 'wait' in params else 300 + # According to the documentation a small random amount of additional wait time is added to the + # supplied maximum wait time to spread out the wake up time of any concurrent requests. This adds + # up to wait / 16 additional time to the maximum duration. Since our goal is actually getting a + # response rather read timeout we will add to the timeout a sligtly bigger value. + kwargs['timeout'] = timeout + max(timeout/15.0, 1) else: kwargs['timeout'] = self._read_timeout token = params.pop('token', self.token) if isinstance(params, dict) else self.token