diff --git a/irrd/mirroring/mirror_runners_import.py b/irrd/mirroring/mirror_runners_import.py index d1b8c1097..a128d2545 100644 --- a/irrd/mirroring/mirror_runners_import.py +++ b/irrd/mirroring/mirror_runners_import.py @@ -47,6 +47,10 @@ def run(self) -> None: self.update_stream_runner.run(serial_newest_seen, database_handler=self.database_handler) self.database_handler.commit() + except OSError as ose: + # I/O errors can occur and should not log a full traceback (#177) + logger.error(f'An error occurred while attempting a mirror update or initial import ' + f'for {self.source}: {ose}') except Exception as exc: logger.error(f'An exception occurred while attempting a mirror update or initial import ' f'for {self.source}: {exc}', exc_info=exc) diff --git a/irrd/mirroring/tests/test_mirror_runners_import.py b/irrd/mirroring/tests/test_mirror_runners_import.py index b289b3e14..90d5e35e4 100644 --- a/irrd/mirroring/tests/test_mirror_runners_import.py +++ b/irrd/mirroring/tests/test_mirror_runners_import.py @@ -81,7 +81,26 @@ def test_update_stream_call(self, monkeypatch, config_override): assert mock_stream_runner.mock_calls[0][0] == 'run' assert mock_stream_runner.mock_calls[0][1] == (424242,) - def test_exception_handling(self, monkeypatch, caplog): + def test_io_exception_handling(self, monkeypatch, caplog): + mock_dh = Mock() + mock_dq = Mock() + mock_full_import_runner = Mock() + + monkeypatch.setattr('irrd.mirroring.mirror_runners_import.DatabaseHandler', lambda: mock_dh) + monkeypatch.setattr('irrd.mirroring.mirror_runners_import.DatabaseStatusQuery', lambda: mock_dq) + monkeypatch.setattr('irrd.mirroring.mirror_runners_import.MirrorFullImportRunner', lambda source: mock_full_import_runner) + mock_full_import_runner.run = Mock(side_effect=ConnectionResetError('test-error')) + + mock_dh.execute_query = lambda q: iter([{'serial_newest_seen': 424242, 'force_reload': False}]) + runner = MirrorImportUpdateRunner(source='TEST') + runner.run() + + assert flatten_mock_calls(mock_dh) == [['close', (), {}]] + assert 'An error occurred while attempting a mirror update or initial import for TEST' in caplog.text + assert 'test-error' in caplog.text + assert 'Traceback' not in caplog.text + + def test_unexpected_exception_handling(self, monkeypatch, caplog): mock_dh = Mock() mock_dq = Mock() mock_full_import_runner = Mock() @@ -98,6 +117,7 @@ def test_exception_handling(self, monkeypatch, caplog): assert flatten_mock_calls(mock_dh) == [['close', (), {}]] assert 'An exception occurred while attempting a mirror update or initial import for TEST' in caplog.text assert 'test-error' in caplog.text + assert 'Traceback' in caplog.text class TestMirrorFullImportRunner: