diff --git a/news.d/bugfix/1743.core.md b/news.d/bugfix/1743.core.md new file mode 100644 index 000000000..e8679f788 --- /dev/null +++ b/news.d/bugfix/1743.core.md @@ -0,0 +1 @@ +Hide `ConnectionResetError` caused by a race condition when Plover is restarted. diff --git a/plover/oslayer/controller.py b/plover/oslayer/controller.py index 70cd138eb..badc1cee3 100644 --- a/plover/oslayer/controller.py +++ b/plover/oslayer/controller.py @@ -27,8 +27,16 @@ def is_owner(self): def force_cleanup(self): assert not self.is_owner - if PLATFORM != "win" and os.path.exists(self._address): - os.unlink(self._address) + if PLATFORM != "win": + try: + os.unlink(self._address) + except FileNotFoundError: + # possible race condition: a ConnectionResetError might be caused + # by the previous instance dying just as this instance tries to + # connect to it. In that case self._address would have existed + # at the creation of controller but now no longer exists. + # We ignore the error + pass return True return False diff --git a/plover/scripts/main.py b/plover/scripts/main.py index b7a5a9773..559ed8291 100644 --- a/plover/scripts/main.py +++ b/plover/scripts/main.py @@ -158,6 +158,7 @@ def main(): # Assume the previous instance died, leaving # a stray socket, try cleaning it... if not controller.force_cleanup(): + log.error("force cleaning failed") raise # ...and restart. code = -1