Skip to content

Commit a8684d7

Browse files
committed
As per celery#5605, the Consul backend does not cleanly associate responses
from Consul with the outbound Celery request that caused it. This leaves it prone to mistaking the (final) response from an operation N as the response to an (early) part of operation N + 1. This changes fix that by using a separate connection for each request. That of course has the downside of (a) being relatively expensive and (b) increasing the rate of connection requests into Consul: - The former is annoying, but at least the backend works reliably. - The latter can cause Consul to reject excessive connection attempt, but if it does, at least it returns a clear indication of this (IIRC, it responds with an HTTP 429"too many connections" indication). Additionally, this issue can be ameliorated by enabling retries in the python-consul2 (which I believe should be turned on regards less to handle transient network issues). This is fixed by the PR in https:/github.com/poppyred/python-consul2/pull/31. Note that we have never seen (b) outside a test specifically trying to hammer the system, but we see (a) all the time in our normal system tests.
1 parent 117cd9c commit a8684d7

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

celery/backends/consul.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ def _init_from_params(self, hostname, port, virtual_host, **params):
4747
logger.debug('Setting on Consul client to connect to %s:%d',
4848
hostname, port)
4949
self.path = virtual_host
50-
self.client = consul.Consul(host=hostname, port=port,
51-
consistency=self.consistency)
50+
self.hostname = hostname
51+
self.port = port
52+
53+
@property
54+
def client(self):
55+
return consul.Consul(host=self.hostname, port=self.port, consistency=self.consistency)
5256

5357
def _key_to_consul_key(self, key):
5458
key = bytes_to_str(key)

0 commit comments

Comments
 (0)