mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Single user mode was waiting for user input and never finish (#634)
Regression was introduced in https://github.com/zalando/patroni/pull/576
This commit is contained in:
+13
-5
@@ -1790,10 +1790,20 @@ $$""".format(name, ' '.join(options)), name, password, password)
|
||||
return self.single_user_mode(options=opts) == 0 or None
|
||||
|
||||
def cancellable_subprocess_call(self, *args, **kwargs):
|
||||
communicate_input = kwargs.pop('communicate_input', None)
|
||||
for s in ('stdin', 'stdout', 'stderr'):
|
||||
kwargs.pop(s, None)
|
||||
|
||||
communicate_input = 'communicate_input' in kwargs
|
||||
if communicate_input:
|
||||
input_data = kwargs.pop('communicate_input', None)
|
||||
if not isinstance(input_data, string_types):
|
||||
input_data = ''
|
||||
if input_data and input_data[-1] != '\n':
|
||||
input_data += '\n'
|
||||
kwargs['stdin'] = subprocess.PIPE
|
||||
kwargs['stdout'] = open(os.devnull, 'w')
|
||||
kwargs['stderr'] = subprocess.STDOUT
|
||||
|
||||
try:
|
||||
with self._cancellable_lock:
|
||||
if self._is_cancelled:
|
||||
@@ -1803,10 +1813,8 @@ $$""".format(name, ' '.join(options)), name, password, password)
|
||||
self._cancellable = subprocess.Popen(*args, **kwargs)
|
||||
|
||||
if communicate_input:
|
||||
kwargs['stdin'] = subprocess.PIPE
|
||||
if communicate_input[-1] != '\n':
|
||||
communicate_input += '\n'
|
||||
self._cancellable.communicate(communicate_input + '\n')
|
||||
if input_data:
|
||||
self._cancellable.communicate(input_data)
|
||||
self._cancellable.stdin.close()
|
||||
|
||||
return self._cancellable.wait()
|
||||
|
||||
@@ -946,7 +946,7 @@ class TestPostgresql(unittest.TestCase):
|
||||
|
||||
def test_cancellable_subprocess_call(self):
|
||||
self.p.cancel()
|
||||
self.assertRaises(PostgresException, self.p.cancellable_subprocess_call)
|
||||
self.assertRaises(PostgresException, self.p.cancellable_subprocess_call, communicate_input=None)
|
||||
|
||||
@patch('patroni.postgresql.polling_loop', Mock(return_value=[0, 0]))
|
||||
def test_cancel(self):
|
||||
|
||||
Reference in New Issue
Block a user