From 8aef454b067adde46a06607b1f145dc092d32698 Mon Sep 17 00:00:00 2001 From: Christoph Heer Date: Tue, 8 Dec 2020 22:18:14 +0100 Subject: [PATCH 1/2] Emit warning if ping socket select takes longer We experienced Zookeeper session timeouts within our applications with Kazoo because of GIL contention blocking the Kazoo thread and its ping loop. The thread will now emit a warning in such a case. --- kazoo/protocol/connection.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py index fc3586c8..94648c2e 100644 --- a/kazoo/protocol/connection.py +++ b/kazoo/protocol/connection.py @@ -589,10 +589,17 @@ def _connect_attempt(self, host, hostip, port, retry): # Ensure our timeout is positive timeout = max([read_timeout / 2.0 - jitter_time, jitter_time]) + select_start_time = time.time() s = self.handler.select([self._socket, self._read_sock], [], [], timeout)[0] if not s: + select_block_time = time.time() - select_start_time + if select_block_time > read_timeout: + self.logger.warning( + "Socket select took longer than expected: %0.5f", + select_block_time + ) if self.ping_outstanding.is_set(): self.ping_outstanding.clear() raise ConnectionDropped( From 9ebaf6a0143a9f0629a9eedb178cc4ea4a8b09df Mon Sep 17 00:00:00 2001 From: Christoph Heer Date: Tue, 8 Dec 2020 22:52:22 +0100 Subject: [PATCH 2/2] Fixed line length --- kazoo/protocol/connection.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py index 94648c2e..275c3771 100644 --- a/kazoo/protocol/connection.py +++ b/kazoo/protocol/connection.py @@ -597,7 +597,8 @@ def _connect_attempt(self, host, hostip, port, retry): select_block_time = time.time() - select_start_time if select_block_time > read_timeout: self.logger.warning( - "Socket select took longer than expected: %0.5f", + "Socket select took longer than expected: " + "%0.5f", select_block_time ) if self.ping_outstanding.is_set():