giampaolo / pyftpdlib

Extremely fast and scalable Python FTP server library
MIT License
1.66k stars 266 forks source link

Windows: PermissionError when choosing port from configured PASV range #627

Closed giampaolo closed 3 months ago

giampaolo commented 3 months ago

Observed during CI tests. We probably want to catch PermissionError and skip to the next configured port.

2024-06-20T23:23:31.6038036Z ================================== FAILURES ===================================
2024-06-20T23:23:31.6038927Z _____________ TestConfigurableOptionsTLSMixin.test_passive_ports ______________
2024-06-20T23:23:31.6039741Z Traceback (most recent call last):
2024-06-20T23:23:31.6047563Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\unittest\case.py", line 57, in testPartExecutor
2024-06-20T23:23:31.6048226Z     yield
2024-06-20T23:23:31.6048794Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\unittest\case.py", line 623, in run
2024-06-20T23:23:31.6049388Z     self._callTestMethod(testMethod)
2024-06-20T23:23:31.6050037Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\unittest\case.py", line 579, in _callTestMethod
2024-06-20T23:23:31.6050647Z     if method() is not None:
2024-06-20T23:23:31.6050914Z        ^^^^^^^^
2024-06-20T23:23:31.6051449Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\test\test_functional.py", line 1864, in test_passive_ports
2024-06-20T23:23:31.6052083Z     assert self.client.makepasv()[1] in _range
2024-06-20T23:23:31.6052692Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\ftplib.py", line 327, in makepasv
2024-06-20T23:23:31.6053302Z     untrusted_host, port = parse227(self.sendcmd('PASV'))
2024-06-20T23:23:31.6053707Z                                     ^^^^^^^^^^^^^^^^^^^^
2024-06-20T23:23:31.6054264Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\ftplib.py", line 281, in sendcmd
2024-06-20T23:23:31.6054789Z     return self.getresp()
2024-06-20T23:23:31.6055031Z            ^^^^^^^^^^^^^^
2024-06-20T23:23:31.6055546Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\ftplib.py", line 244, in getresp
2024-06-20T23:23:31.6056231Z     resp = self.getmultiline()
2024-06-20T23:23:31.6056500Z            ^^^^^^^^^^^^^^^^^^^
2024-06-20T23:23:31.6057032Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\ftplib.py", line 230, in getmultiline
2024-06-20T23:23:31.6057582Z     line = self.getline()
2024-06-20T23:23:31.6057816Z            ^^^^^^^^^^^^^^
2024-06-20T23:23:31.6058288Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\ftplib.py", line 218, in getline
2024-06-20T23:23:31.6058803Z     raise EOFError
2024-06-20T23:23:31.6059004Z EOFError
2024-06-20T23:23:31.6059303Z ------------------------------ Captured log call ------------------------------
2024-06-20T23:23:31.6060168Z ERROR    pyftpdlib:handlers.py:2053 unhandled exception in instance <TLS_FTPHandler(id=2369463484496, addr='127.0.0.1:51272', ssl=True, user='user')>
2024-06-20T23:23:31.6060924Z Traceback (most recent call last):
2024-06-20T23:23:31.6061458Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\asyncore.py", line 88, in read
2024-06-20T23:23:31.6061982Z     obj.handle_read_event()
2024-06-20T23:23:31.6062504Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\handlers.py", line 3507, in handle_read_event
2024-06-20T23:23:31.6063032Z     super().handle_read_event()
2024-06-20T23:23:31.6063605Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\asyncore.py", line 425, in handle_read_event
2024-06-20T23:23:31.6064175Z     self.handle_read()
2024-06-20T23:23:31.6064619Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\ioloop.py", line 992, in handle_read
2024-06-20T23:23:31.6065128Z     asynchat.async_chat.handle_read(self)
2024-06-20T23:23:31.6065781Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\asynchat.py", line 178, in handle_read
2024-06-20T23:23:31.6066330Z     self.found_terminator()
2024-06-20T23:23:31.6066825Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\handlers.py", line 1629, in found_terminator
2024-06-20T23:23:31.6067376Z     self.pre_process_command(line, cmd, arg)
2024-06-20T23:23:31.6067964Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\handlers.py", line 1748, in pre_process_command
2024-06-20T23:23:31.6068523Z     self.process_command(cmd, arg, **kwargs)
2024-06-20T23:23:31.6069081Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\handlers.py", line 3885, in process_command
2024-06-20T23:23:31.6069766Z     FTPHandler.process_command(self, cmd, *args, **kwargs)
2024-06-20T23:23:31.6070379Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\handlers.py", line 1759, in process_command
2024-06-20T23:23:31.6070873Z     method(*args, **kwargs)
2024-06-20T23:23:31.6071332Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\handlers.py", line 2292, in ftp_PASV
2024-06-20T23:23:31.6071827Z     self._make_epasv(extmode=False)
2024-06-20T23:23:31.6072329Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\handlers.py", line 2208, in _make_epasv
2024-06-20T23:23:31.6072893Z     self._dtp_acceptor = self.passive_dtp(self, extmode)
2024-06-20T23:23:31.6073285Z                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-06-20T23:23:31.6073801Z   File "D:\a\pyftpdlib\pyftpdlib\pyftpdlib\handlers.py", line 479, in __init__
2024-06-20T23:23:31.6074280Z     self.bind((local_ip, port))
2024-06-20T23:23:31.6074786Z   File "C:\hostedtoolcache\windows\Python\3.11.9\x64\Lib\asyncore.py", line 331, in bind
2024-06-20T23:23:31.6075322Z     return self.socket.bind(addr)
2024-06-20T23:23:31.6075601Z            ^^^^^^^^^^^^^^^^^^^^^^
2024-06-20T23:23:31.6076200Z PermissionError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions