Fix recursive BrokenPipeException on disconnect
authorJeremy Stanley <fungi@yuggoth.org>
Tue, 23 Feb 2016 22:32:27 +0000 (22:32 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Tue, 23 Feb 2016 22:32:27 +0000 (22:32 +0000)
When an admin user has a broken pipe, attempting to log
BrokenPipeException errors to their socket raises another until the
max recursion depth is hit. Set the current user's state to
disconnecting before logging the error instead of after, so as to
avoid this loop.

lib/mudpy/misc.py

index ea18ffb..41d3ab6 100644 (file)
@@ -840,14 +840,14 @@ class User:
         if self.output_queue:
             try:
                 self.connection.send(self.output_queue[0])
-                del self.output_queue[0]
             except BrokenPipeError:
                 if self.account and self.account.get("name"):
                     account = self.account.get("name")
                 else:
                     account = "an unknown user"
-                log("Broken pipe sending to %s." % account, 7)
                 self.state = "disconnecting"
+                log("Broken pipe sending to %s." % account, 7)
+            del self.output_queue[0]
 
     def enqueue_input(self):
         """Process and enqueue any new input."""