Explorar o código

Adds redis_socket_connect_timeout setting, and make sure its not set with Unix socket

Ask Solem %!s(int64=8) %!d(string=hai) anos
pai
achega
fcecfb0877

+ 1 - 0
celery/app/defaults.py

@@ -158,6 +158,7 @@ NAMESPACES = Namespace(
         password=Option(type='string'),
         password=Option(type='string'),
         port=Option(type='int'),
         port=Option(type='int'),
         socket_timeout=Option(120.0, type='float'),
         socket_timeout=Option(120.0, type='float'),
+        socket_connect_timeout=Option(None, type='float'),
     ),
     ),
     result=Namespace(
     result=Namespace(
         __old__=old_ns('celery_result'),
         __old__=old_ns('celery_result'),

+ 9 - 8
celery/backends/redis.py

@@ -119,13 +119,18 @@ class RedisBackend(base.BaseKeyValueStoreBackend, async.AsyncBackendMixin):
             self.max_connections)
             self.max_connections)
         self._ConnectionPool = connection_pool
         self._ConnectionPool = connection_pool
 
 
+        socket_timeout = _get('redis_socket_timeout')
+        socket_connect_timeout = _get('redis_socket_connect_timeout')
+
         self.connparams = {
         self.connparams = {
             'host': _get('redis_host') or 'localhost',
             'host': _get('redis_host') or 'localhost',
             'port': _get('redis_port') or 6379,
             'port': _get('redis_port') or 6379,
             'db': _get('redis_db') or 0,
             'db': _get('redis_db') or 0,
             'password': _get('redis_password'),
             'password': _get('redis_password'),
-            'socket_timeout': _get('redis_socket_timeout'),
             'max_connections': self.max_connections,
             'max_connections': self.max_connections,
+            'socket_timeout': socket_timeout and float(socket_timeout),
+            'socket_connect_timeout':
+                socket_connect_timeout and float(socket_connect_timeout),
         }
         }
         if url:
         if url:
             self.connparams = self._params_from_url(url, self.connparams)
             self.connparams = self._params_from_url(url, self.connparams)
@@ -157,6 +162,7 @@ class RedisBackend(base.BaseKeyValueStoreBackend, async.AsyncBackendMixin):
             # host+port are invalid options when using this connection type.
             # host+port are invalid options when using this connection type.
             connparams.pop('host', None)
             connparams.pop('host', None)
             connparams.pop('port', None)
             connparams.pop('port', None)
+            connparams.pop('socket_connect_timeout')
         else:
         else:
             connparams['db'] = path
             connparams['db'] = path
 
 
@@ -290,14 +296,9 @@ class RedisBackend(base.BaseKeyValueStoreBackend, async.AsyncBackendMixin):
                 ChordError('Join error: {0!r}'.format(exc)),
                 ChordError('Join error: {0!r}'.format(exc)),
             )
             )
 
 
-    def _create_client(self, socket_timeout=None, socket_connect_timeout=None,
-                       **params):
+    def _create_client(self, **params):
         return self.redis.StrictRedis(
         return self.redis.StrictRedis(
-            connection_pool=self.ConnectionPool(
-                socket_timeout=socket_timeout and float(socket_timeout),
-                socket_connect_timeout=socket_connect_timeout and float(
-                    socket_connect_timeout),
-                **params),
+            connection_pool=self.ConnectionPool(**params),
         )
         )
 
 
     @property
     @property

+ 14 - 2
docs/userguide/configuration.rst

@@ -888,6 +888,18 @@ Default: No limit.
 Maximum number of connections available in the Redis connection
 Maximum number of connections available in the Redis connection
 pool used for sending and retrieving results.
 pool used for sending and retrieving results.
 
 
+.. setting:: redis_socket_connect_timeout
+
+``redis_socket_connect_timeout``
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+.. versionadded:: 5.0.1
+
+Default: :const:`None`
+
+Socket timeout for connections to Redis from the result backend
+in seconds (int/float)
+
 .. setting:: redis_socket_timeout
 .. setting:: redis_socket_timeout
 
 
 ``redis_socket_timeout``
 ``redis_socket_timeout``
@@ -895,8 +907,8 @@ pool used for sending and retrieving results.
 
 
 Default: 5.0 seconds.
 Default: 5.0 seconds.
 
 
-Socket timeout for connections to Redis from the result backend
-in seconds (int/float)
+Socket timeout for reading/writing operations to the Redis server
+in seconds (int/float), used by the redis result backend.
 
 
 .. _conf-cassandra-result-backend:
 .. _conf-cassandra-result-backend:
 
 

+ 8 - 0
t/unit/backends/test_redis.py

@@ -150,6 +150,8 @@ class test_RedisBackend:
             self.Backend(app=self.app)
             self.Backend(app=self.app)
 
 
     def test_url(self):
     def test_url(self):
+        self.app.conf.redis_socket_timeout = 30.0
+        self.app.conf.redis_socket_connect_timeout = 100.0
         x = self.Backend(
         x = self.Backend(
             'redis://:bosco@vandelay.com:123//1', app=self.app,
             'redis://:bosco@vandelay.com:123//1', app=self.app,
         )
         )
@@ -158,8 +160,12 @@ class test_RedisBackend:
         assert x.connparams['db'] == 1
         assert x.connparams['db'] == 1
         assert x.connparams['port'] == 123
         assert x.connparams['port'] == 123
         assert x.connparams['password'] == 'bosco'
         assert x.connparams['password'] == 'bosco'
+        assert x.connparams['socket_timeout'] == 30.0
+        assert x.connparams['socket_connect_timeout'] == 100.0
 
 
     def test_socket_url(self):
     def test_socket_url(self):
+        self.app.conf.redis_socket_timeout = 30.0
+        self.app.conf.redis_socket_connect_timeout = 100.0
         x = self.Backend(
         x = self.Backend(
             'socket:///tmp/redis.sock?virtual_host=/3', app=self.app,
             'socket:///tmp/redis.sock?virtual_host=/3', app=self.app,
         )
         )
@@ -169,6 +175,8 @@ class test_RedisBackend:
                 redis.UnixDomainSocketConnection)
                 redis.UnixDomainSocketConnection)
         assert 'host' not in x.connparams
         assert 'host' not in x.connparams
         assert 'port' not in x.connparams
         assert 'port' not in x.connparams
+        assert x.connparams['socket_timeout'] == 30.0
+        assert 'socket_connect_timeout' not in x.connparams
         assert x.connparams['db'] == 3
         assert x.connparams['db'] == 3
 
 
     def test_compat_propertie(self):
     def test_compat_propertie(self):