diff --git a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py index 237a89145f..6f0ab84aef 100644 --- a/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py +++ b/deltachat-rpc-client/src/deltachat_rpc_client/rpc.py @@ -149,7 +149,10 @@ def start(self) -> None: def close(self) -> None: """Terminate RPC server process and wait until the reader loop finishes.""" self.closing = True - self.stop_io_for_all_accounts() + # JSON-RPC error may happen if RPC server process has crashed already. + # We still want to shutdown all threads in this case. + with contextlib.suppress(JsonRpcError): + self.stop_io_for_all_accounts() # Let `events_loop` stop cleanly on `closing` before the pipe goes away, # otherwise it might exit through an "RPC server closed" error instead. self.events_thread.join() diff --git a/deltachat-rpc-client/tests/test_something.py b/deltachat-rpc-client/tests/test_something.py index 70743f4be9..148d8cb998 100644 --- a/deltachat-rpc-client/tests/test_something.py +++ b/deltachat-rpc-client/tests/test_something.py @@ -35,6 +35,19 @@ def test_sleep(rpc) -> None: assert sleep_5_future in pending +def test_shutdown(rpc) -> None: + """Test RPC client shutdown if RPC server process is terminated. + + This is a regression test, at the time of adding it RPC client + did not terminate all threads and python process did not exit. + Shutting down all threads is tested implicitly by pytest-timeout. + """ + rpc.process.kill() + rpc.process.wait() + with pytest.raises(JsonRpcError): + rpc.get_system_info() + + def test_email_address_validity(rpc) -> None: valid_addresses = [ "email@example.com",