Skip to content

Commit 0611eaf

Browse files
authored
bpo-44359: Fix test_ftplib unhandled thread exceptions (GH-31069)
test_ftplib now silently ignores socket errors to prevent logging unhandled threading exceptions.
1 parent 53c7808 commit 0611eaf

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Lib/test/test_ftplib.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@
5656
"type=file;perm=r;unique==SGP2; file \xAE non-ascii char\r\n")
5757

5858

59+
def default_error_handler():
60+
# bpo-44359: Silently ignore socket errors. Such errors occur when a client
61+
# socket is closed, in TestFTPClass.tearDown() and makepasv() tests, and
62+
# the server gets an error on its side.
63+
pass
64+
65+
5966
class DummyDTPHandler(asynchat.async_chat):
6067
dtp_conn_closed = False
6168

@@ -87,7 +94,7 @@ def push(self, what):
8794
super(DummyDTPHandler, self).push(what.encode(self.encoding))
8895

8996
def handle_error(self):
90-
raise Exception
97+
default_error_handler()
9198

9299

93100
class DummyFTPHandler(asynchat.async_chat):
@@ -137,7 +144,7 @@ def found_terminator(self):
137144
self.push('550 command "%s" not understood.' %cmd)
138145

139146
def handle_error(self):
140-
raise Exception
147+
default_error_handler()
141148

142149
def push(self, data):
143150
asynchat.async_chat.push(self, data.encode(self.encoding) + b'\r\n')
@@ -315,7 +322,7 @@ def writable(self):
315322
return 0
316323

317324
def handle_error(self):
318-
raise Exception
325+
default_error_handler()
319326

320327

321328
if ssl is not None:
@@ -418,7 +425,7 @@ def recv(self, buffer_size):
418425
raise
419426

420427
def handle_error(self):
421-
raise Exception
428+
default_error_handler()
422429

423430
def close(self):
424431
if (isinstance(self.socket, ssl.SSLSocket) and
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
test_ftplib now silently ignores socket errors to prevent logging unhandled
2+
threading exceptions. Patch by Victor Stinner.

0 commit comments

Comments
 (0)