From acb2ca79d9e3b6d851a2c017b79a314b9f5baf61 Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Fri, 6 Aug 2021 08:58:11 -0700 Subject: [PATCH] Fix traceback that can occur when dumping a database (#440). --- NEWS | 3 ++- borgmatic/execute.py | 5 +++-- setup.py | 2 +- tests/integration/test_execute.py | 31 +++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/NEWS b/NEWS index d196df9..19e605a 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,6 @@ -1.5.18.dev0 +1.5.18 * #389: Fix "message too long" error when logging to rsyslog. + * #440: Fix traceback that can occur when dumping a database. 1.5.17 * #437: Fix error when configuration file contains "umask" option. diff --git a/borgmatic/execute.py b/borgmatic/execute.py index db6da64..a6741c9 100644 --- a/borgmatic/execute.py +++ b/borgmatic/execute.py @@ -81,6 +81,7 @@ def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path): for other_process in processes: if ( other_process.poll() is None + and other_process.stdout and other_process.stdout not in output_buffers ): # Add the process's output to output_buffers to ensure it'll get read. @@ -138,10 +139,10 @@ def log_outputs(processes, exclude_stdouts, output_log_level, borg_local_path): if not output_buffer: continue - while True: + while True: # pragma: no cover remaining_output = output_buffer.readline().rstrip().decode() - if not remaining_output: # pragma: no cover + if not remaining_output: break logger.log(output_log_level, remaining_output) diff --git a/setup.py b/setup.py index 5f5330f..49b93d0 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import find_packages, setup -VERSION = '1.5.18.dev0' +VERSION = '1.5.18' setup( diff --git a/tests/integration/test_execute.py b/tests/integration/test_execute.py index 7320658..51aa5f4 100644 --- a/tests/integration/test_execute.py +++ b/tests/integration/test_execute.py @@ -162,6 +162,37 @@ def test_log_outputs_vents_other_processes_when_one_exits(): ) +def test_log_outputs_does_not_error_when_one_process_exits(): + flexmock(module.logger).should_receive('log') + flexmock(module).should_receive('command_for_process').and_return('grep') + + process = subprocess.Popen( + [ + sys.executable, + '-c', + "import random, string; print(''.join(random.choice(string.ascii_letters) for _ in range(40000)))", + ], + stdout=None, # Specifically test the case of a process without stdout captured. + stderr=None, + ) + other_process = subprocess.Popen( + ['true'], stdin=process.stdout, stdout=subprocess.PIPE, stderr=subprocess.STDOUT + ) + flexmock(module).should_receive('output_buffer_for_process').with_args( + process, (process.stdout,) + ).and_return(process.stderr) + flexmock(module).should_receive('output_buffer_for_process').with_args( + other_process, (process.stdout,) + ).and_return(other_process.stdout) + + module.log_outputs( + (process, other_process), + exclude_stdouts=(process.stdout,), + output_log_level=logging.INFO, + borg_local_path='borg', + ) + + def test_log_outputs_truncates_long_error_output(): flexmock(module).ERROR_OUTPUT_MAX_LINE_COUNT = 0 flexmock(module.logger).should_receive('log')