Compatibility with python3 (#883)

Change of `loop_wait` was causing Patroni to disconnect from zookeeper and never reconnect back. The error was happening only with python3 due to a difference in implementation of `select.select` function.
This commit is contained in:
Alexander Kukushkin
2018-11-30 11:40:34 +01:00
committed by GitHub
parent f8f928420d
commit 9bf074acfb
2 changed files with 13 additions and 0 deletions
+8
View File
@@ -1,5 +1,6 @@
import json
import logging
import select
import time
from kazoo.client import KazooClient, KazooState, KazooRetry
@@ -45,6 +46,13 @@ class PatroniSequentialThreadingHandler(SequentialThreadingHandler):
args[1] = max(self._connect_timeout, args[1]/10.0)
return super(PatroniSequentialThreadingHandler, self).create_connection(*args, **kwargs)
def select(self, *args, **kwargs):
"""Python3 raises `ValueError` if socket is closed, because fd == -1"""
try:
return super(PatroniSequentialThreadingHandler, self).select(*args, **kwargs)
except ValueError as e:
raise select.error(9, str(e))
class ZooKeeper(AbstractDCS):
+5
View File
@@ -1,3 +1,4 @@
import select
import six
import unittest
@@ -115,6 +116,10 @@ class TestPatroniSequentialThreadingHandler(unittest.TestCase):
self.assertIsNotNone(self.handler.create_connection((), 40))
self.assertIsNotNone(self.handler.create_connection(timeout=40))
@patch.object(SequentialThreadingHandler, 'select', Mock(side_effect=ValueError))
def test_select(self):
self.assertRaises(select.error, self.handler.select)
class TestZooKeeper(unittest.TestCase):