Skip to content

ConectionResetError, again #1738

@user202729

Description

@user202729

I encounter the issue again after apply #1723 .

My guess for what happened is a race condition.

diff --git a/plover/oslayer/controller.py b/plover/oslayer/controller.py
index 724f792..d0c4ce5 100644
--- a/plover/oslayer/controller.py
+++ b/plover/oslayer/controller.py
@@ -28,8 +28,16 @@ class Controller:
 
     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 7329e4a..6775f3f 100644
--- a/plover/scripts/main.py
+++ b/plover/scripts/main.py
@@ -140,6 +140,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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions