From 43c6279a7eff0df7ab22155fb6c165f551cdcf8d Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Thu, 30 Aug 2018 20:41:21 +0000 Subject: [PATCH] Drop expired connections before retrieving from the queue If all the connections in the queue have expired, we don't want to return any of them. Because we previously dropped connections only after retrieval, it was possible we would choose and return a dead connection. Doing the cleanup first should prevent that. Change-Id: I650537e7b44d6bdd552def6a3b2de42a60ed9b94 Closes-Bug: 1775341 --- oslo_cache/_memcache_pool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oslo_cache/_memcache_pool.py b/oslo_cache/_memcache_pool.py index 416d0a6e..bd1a5296 100644 --- a/oslo_cache/_memcache_pool.py +++ b/oslo_cache/_memcache_pool.py @@ -123,6 +123,7 @@ class ConnectionPool(queue.Queue): @contextlib.contextmanager def acquire(self): self._trace_logger('Acquiring connection') + self._drop_expired_connections() try: conn = self.get(timeout=self._connection_get_timeout) except queue.Empty: @@ -135,7 +136,6 @@ class ConnectionPool(queue.Queue): yield conn finally: self._trace_logger('Releasing connection %s', id(conn)) - self._drop_expired_connections() try: # super() cannot be used here because Queue in stdlib is an # old-style class