From f8685230a5d55d4755427e3fcc8cab0eb57cd37c Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Sun, 23 Jul 2023 15:59:56 +0200 Subject: Make sure ipc.shutdown() can be called twice We still want to make sure that IPC is shut down early when using :restart. However, doing it again should be a nop when quitting qutebrowser then shuts it down again. This accidentally worked before 6373959 ("Always delay stage 2 shutdown, not only with prompts"), because most operations in shutdown() just happened to be idempotent. Because we never returned to the Qt mainloop between the first and the second call, the self._server.deleteLater() call didn't actually delete anything yet. After that change, however, we do end up in shutdown() again with an actually deleted C++ QLocalServer object, so trying to call .close() on it again failed with a RuntimeError. Fixed #7681 --- qutebrowser/misc/ipc.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/qutebrowser/misc/ipc.py b/qutebrowser/misc/ipc.py index 9b7e30609..15b158491 100644 --- a/qutebrowser/misc/ipc.py +++ b/qutebrowser/misc/ipc.py @@ -427,11 +427,19 @@ class IPCServer(QObject): @pyqtSlot() def shutdown(self): """Shut down the IPC server cleanly.""" + if self._server is None: + # We can get called twice when using :restart -- there, IPC is shut down + # early to avoid processing new connections while shutting down, and then + # we get called again when the application is about to quit. + return + log.ipc.debug("Shutting down IPC (socket 0x{:x})".format( id(self._socket))) + if self._socket is not None: self._socket.deleteLater() self._socket = None + self._timer.stop() if self._atime_timer is not None: # pragma: no branch self._atime_timer.stop() @@ -439,9 +447,11 @@ class IPCServer(QObject): self._atime_timer.timeout.disconnect(self.update_atime) except TypeError: pass + self._server.close() self._server.deleteLater() self._remove_server() + self._server = None def send_to_running_instance(socketname, command, target_arg, *, socket=None): -- cgit v1.2.3-54-g00ecf