]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-44359: Fix test_ftplib unhandled thread exceptions (GH-31069)
authorVictor Stinner <vstinner@python.org>
Wed, 2 Feb 2022 01:47:40 +0000 (02:47 +0100)
committerGitHub <noreply@github.com>
Wed, 2 Feb 2022 01:47:40 +0000 (02:47 +0100)
test_ftplib now silently ignores socket errors to prevent logging
unhandled threading exceptions.

Lib/test/test_ftplib.py
Misc/NEWS.d/next/Tests/2022-02-02-02-24-04.bpo-44359.kPPSmN.rst [new file with mode: 0644]

index 56e3d8ab8528afb4840a6ef1b4c11bfdb160387c..2f5cc06ca4b9a56b57a9a6f227c71bf62fb8b858 100644 (file)
@@ -56,6 +56,13 @@ MLSD_DATA = ("type=cdir;perm=el;unique==keVO1+ZF4; test\r\n"
              "type=file;perm=r;unique==SGP2; file \xAE non-ascii char\r\n")
 
 
+def default_error_handler():
+    # bpo-44359: Silently ignore socket errors. Such errors occur when a client
+    # socket is closed, in TestFTPClass.tearDown() and makepasv() tests, and
+    # the server gets an error on its side.
+    pass
+
+
 class DummyDTPHandler(asynchat.async_chat):
     dtp_conn_closed = False
 
@@ -87,7 +94,7 @@ class DummyDTPHandler(asynchat.async_chat):
         super(DummyDTPHandler, self).push(what.encode(self.encoding))
 
     def handle_error(self):
-        raise Exception
+        default_error_handler()
 
 
 class DummyFTPHandler(asynchat.async_chat):
@@ -137,7 +144,7 @@ class DummyFTPHandler(asynchat.async_chat):
             self.push('550 command "%s" not understood.' %cmd)
 
     def handle_error(self):
-        raise Exception
+        default_error_handler()
 
     def push(self, data):
         asynchat.async_chat.push(self, data.encode(self.encoding) + b'\r\n')
@@ -315,7 +322,7 @@ class DummyFTPServer(asyncore.dispatcher, threading.Thread):
         return 0
 
     def handle_error(self):
-        raise Exception
+        default_error_handler()
 
 
 if ssl is not None:
@@ -418,7 +425,7 @@ if ssl is not None:
                 raise
 
         def handle_error(self):
-            raise Exception
+            default_error_handler()
 
         def close(self):
             if (isinstance(self.socket, ssl.SSLSocket) and
diff --git a/Misc/NEWS.d/next/Tests/2022-02-02-02-24-04.bpo-44359.kPPSmN.rst b/Misc/NEWS.d/next/Tests/2022-02-02-02-24-04.bpo-44359.kPPSmN.rst
new file mode 100644 (file)
index 0000000..00c29b1
--- /dev/null
@@ -0,0 +1,2 @@
+test_ftplib now silently ignores socket errors to prevent logging unhandled
+threading exceptions. Patch by Victor Stinner.