From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Wed, 2 Feb 2022 02:16:58 +0000 (-0800) Subject: bpo-44359: Fix test_ftplib unhandled thread exceptions (GH-31069) X-Git-Tag: v3.9.11~103 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0371e5d7f1248abb0712fc98c3135d01d265cec8;p=thirdparty%2FPython%2Fcpython.git bpo-44359: Fix test_ftplib unhandled thread exceptions (GH-31069) test_ftplib now silently ignores socket errors to prevent logging unhandled threading exceptions. (cherry picked from commit 0611eafc709cbe8a2a0bdde082d25df0c5034de7) Co-authored-by: Victor Stinner --- diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index 6f8f977b3950..b51e5440800c 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -49,6 +49,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 @@ -80,7 +87,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): @@ -130,7 +137,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') @@ -308,7 +315,7 @@ class DummyFTPServer(asyncore.dispatcher, threading.Thread): return 0 def handle_error(self): - raise Exception + default_error_handler() if ssl is not None: @@ -411,7 +418,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 index 000000000000..00c29b1ca408 --- /dev/null +++ b/Misc/NEWS.d/next/Tests/2022-02-02-02-24-04.bpo-44359.kPPSmN.rst @@ -0,0 +1,2 @@ +test_ftplib now silently ignores socket errors to prevent logging unhandled +threading exceptions. Patch by Victor Stinner.