|
|
92ac25a |
From 8a76de29e1ceebcde517c6491de190de4e005303 Mon Sep 17 00:00:00 2001
|
|
|
92ac25a |
From: shangxdy <shang.xiaodong@zte.com.cn>
|
|
|
92ac25a |
Date: Thu, 4 Jan 2018 10:24:06 +0800
|
|
|
92ac25a |
Subject: [PATCH 1/9] Modify connection timeout process
|
|
|
92ac25a |
|
|
|
92ac25a |
When connection to gearman server is timeout, it's necessary to
|
|
|
92ac25a |
release lock before raising a exception, otherwise the client may
|
|
|
92ac25a |
be dead locked.
|
|
|
92ac25a |
|
|
|
92ac25a |
Change-Id: Idc9c9c4bd439b122dc7855ca05d962c4e6687829
|
|
|
92ac25a |
Signed-off-by: shangxdy <shang.xiaodong@zte.com.cn>
|
|
|
92ac25a |
Signed-off-by: Matthieu Huin <mhuin@redhat.com>
|
|
|
92ac25a |
---
|
|
|
92ac25a |
gear/__init__.py | 21 ++++++++++++---------
|
|
|
92ac25a |
1 file changed, 12 insertions(+), 9 deletions(-)
|
|
|
92ac25a |
|
|
|
92ac25a |
diff --git a/gear/__init__.py b/gear/__init__.py
|
|
|
92ac25a |
index 0a78fe4..7695490 100644
|
|
|
92ac25a |
--- a/gear/__init__.py
|
|
|
92ac25a |
+++ b/gear/__init__.py
|
|
|
92ac25a |
@@ -1221,15 +1221,18 @@ class BaseClient(BaseClientServer):
|
|
|
92ac25a |
start_time = time.time()
|
|
|
92ac25a |
while self.running:
|
|
|
92ac25a |
self.connections_condition.acquire()
|
|
|
92ac25a |
- while self.running and not self.active_connections:
|
|
|
92ac25a |
- if timeout is not None:
|
|
|
92ac25a |
- self._checkTimeout(start_time, timeout)
|
|
|
92ac25a |
- self.log.debug("Waiting for at least one active connection")
|
|
|
92ac25a |
- self.connections_condition.wait(timeout=1)
|
|
|
92ac25a |
- if self.active_connections:
|
|
|
92ac25a |
- self.log.debug("Active connection found")
|
|
|
92ac25a |
- connected = True
|
|
|
92ac25a |
- self.connections_condition.release()
|
|
|
92ac25a |
+ try:
|
|
|
92ac25a |
+ while self.running and not self.active_connections:
|
|
|
92ac25a |
+ if timeout is not None:
|
|
|
92ac25a |
+ self._checkTimeout(start_time, timeout)
|
|
|
92ac25a |
+ self.log.debug("Waiting for at least one active "
|
|
|
92ac25a |
+ "connection")
|
|
|
92ac25a |
+ self.connections_condition.wait(timeout=1)
|
|
|
92ac25a |
+ if self.active_connections:
|
|
|
92ac25a |
+ self.log.debug("Active connection found")
|
|
|
92ac25a |
+ connected = True
|
|
|
92ac25a |
+ finally:
|
|
|
92ac25a |
+ self.connections_condition.release()
|
|
|
92ac25a |
if connected:
|
|
|
92ac25a |
return
|
|
|
92ac25a |
|
|
|
92ac25a |
--
|
|
|
92ac25a |
2.31.1
|
|
|
92ac25a |
|