New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ftplib.retrlines('LIST') hangs at the end of listing (SocketIO.close() doesn't close the socket) #49041
Comments
The python program crashes (stops responding) both from the command line I have to close the window (both window shell and IDLE). No other key Python env (from IDLE): Program: import ftplib
ftp = ftplib.FTP('ftp.edgecastcdn.net', user='theusername',
passwd='thepassword')
ftp.cwd('chrismahan-675')
ftp.dir()
#ftp.retrlines('LIST')
ftp.close() The username and password are correct. This runs on a Windows Server 2003 Standard Edition, Service Pack 2. This is also a completely clean install of Python 3.0. I installed it, Python 2.5 is installed on this server and runs fine. Any questions: chris.mahan@gmail.com |
Update: Ran the same code with python 2.6.1 on the same computer, and |
Can you paste the expected result of ftp.retrlines('LIST')? Does a |
the output: just before the non-responsiveness: -rwxrwxrwx 1 nobody nogroup 3905538 Dec 29 09:51 Bronski Beat - |
Added file screenshot of filezilla view of the folder in question. |
The list does not seem to contain non-ascii characters. |
I'm unable to reproduce the issue. I tried to create files on my FTP |
Hi Chris Since dir calls retrlines and retrlines has a 'while 1:' loop, the bug Can you put some print diagnostics inside Lib/ftplib.py->FTP.retrlines HTH, |
<your ftp object>.set_debuglevel(2) already prints a lot of |
I modified the program by adding line: ftp.set_debuglevel(2) import ftplib
ftp = ftplib.FTP('ftp.edgecastcdn.net', user='myuserid',
passwd='mypassword')
ftp.set_debuglevel(2)
ftp.cwd('chrismahan-675')
ftp.dir()
#ftp.retrlines('LIST')
ftp.close()
END LISTING Running from idle 1.2.4 with python 2.5.4 gives this output: *cmd* 'CWD chrismahan-675' Then running with idle 3.0 with python 3.0 gives the following result. *cmd* 'CWD chrismahan-675' Note that the last two lines are missing. From a command prompt: same command prompt but with python 2.5: C:\>c:\python25\python.exe c:\python_scripts\python3\candee_processor.py C:\> |
I went into the source for Libs/ftplib.py and I noted that line 423 is: if self.debugging > 2: print('*retr*', repr(line)) so I changed the debuglevel to 3, as such: ftp.set_debuglevel(3) -rwxrwxrwx 1 nobody nogroup 6465 Dec 28 13:53 test9_sm.flv.jpg First line, the last line of the listing. still digging |
I added the following two lines and I was able to run the code. Before: After: As a patch: 426,427d425 What else do I need to do? |
Can you paste the full output with debuglevel=3? "if not line:" should be equivalent to "if len(line) == 0:" and to "if ftp.dir() is equivalent to ftp.retrlines('LIST'). By default, the socket created to get the result of LIST has no fp is a io.BufferedReader(SocketIO(socket, "r"), |
Full output with debuglevel 3 *cmd* 'CWD chrismahan-675' |
haypo writes:
Even if the server closed the socket and fp.readline() returned an empty |
I'm unable to reproduce the issue. < ftp = ftplib.FTP('ftp.edgecastcdn.net', user='theusername',
|
Per Giampaolo's suggestion, I added the timeout. Program listing and -----begin listing---- import ftplib
ftp = ftplib.FTP('ftp.edgecastcdn.net', user='theusername',
passwd='thepassword', timeout=2)
ftp.set_debuglevel(3)
ftp.cwd('chrismahan-675')
ftp.dir()
#ftp.retrlines('LIST')
ftp.close()
----end listing *cmd* 'CWD chrismahan-675'
*put* 'CWD chrismahan-675\r\n'
*get* '250 CWD command successful\n'
*resp* '250 CWD command successful'
*cmd* 'TYPE A'
*put* 'TYPE A\r\n'
*get* '200 Type set to A\n'
*resp* '200 Type set to A'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (72,21,82,190,172,22).\n'
*resp* '227 Entering Passive Mode (72,21,82,190,172,22).'
*cmd* 'LIST'
*put* 'LIST\r\n'
*get* '150 Opening ASCII mode data connection for file list\n'
*resp* '150 Opening ASCII mode data connection for file list'
*retr* '-rwxrwxrwx 1 nobody nogroup 3905538 Dec 29 09:51 Bronski
Beat - Why.mp3\n'
-rwxrwxrwx 1 nobody nogroup 3905538 Dec 29 09:51 Bronski Beat -
Why.mp3
*retr* '-rwxrwxrwx 1 nobody nogroup 873966 Dec 28 13:53 test9.avi\n'
-rwxrwxrwx 1 nobody nogroup 873966 Dec 28 13:53 test9.avi
*retr* '-rwxrwxrwx 1 nobody nogroup 2512653 Dec 29 08:28
test9_lg.wmv\n'
-rwxrwxrwx 1 nobody nogroup 2512653 Dec 29 08:28 test9_lg.wmv
*retr* '-rwxrwxrwx 1 nobody nogroup 6549 Dec 29 08:28
test9_lg.wmv.jpg\n'
-rwxrwxrwx 1 nobody nogroup 6549 Dec 29 08:28 test9_lg.wmv.jpg
*retr* '-rwxrwxrwx 1 nobody nogroup 1788466 Dec 29 03:04
test9_med.flv\n'
-rwxrwxrwx 1 nobody nogroup 1788466 Dec 29 03:04 test9_med.flv
*retr* '-rwxrwxrwx 1 nobody nogroup 6394 Dec 29 03:04
test9_med.flv.jpg\n'
-rwxrwxrwx 1 nobody nogroup 6394 Dec 29 03:04 test9_med.flv.jpg
*retr* '-rwxrwxrwx 1 nobody nogroup 1263041 Dec 28 13:53
test9_sm.flv\n'
-rwxrwxrwx 1 nobody nogroup 1263041 Dec 28 13:53 test9_sm.flv
*retr* '-rwxrwxrwx 1 nobody nogroup 6465 Dec 28 13:53
test9_sm.flv.jpg\n'
-rwxrwxrwx 1 nobody nogroup 6465 Dec 28 13:53 test9_sm.flv.jpg
*retr* ''
Traceback (most recent call last):
File "C:\python_scripts\python3\candee_processor.py", line 6, in <module>
ftp.dir()
File "c:\python30\lib\ftplib.py", line 511, in dir
self.retrlines(cmd, func)
File "c:\python30\lib\ftplib.py", line 433, in retrlines
return self.voidresp()
File "c:\python30\lib\ftplib.py", line 225, in voidresp
resp = self.getresp()
File "c:\python30\lib\ftplib.py", line 211, in getresp
resp = self.getmultiline()
File "c:\python30\lib\ftplib.py", line 197, in getmultiline
line = self.getline()
File "c:\python30\lib\ftplib.py", line 184, in getline
line = self.file.readline()
File "C:\Python30\lib\io.py", line 1813, in readline
while self._read_chunk():
File "C:\Python30\lib\io.py", line 1560, in _read_chunk
input_chunk = self.buffer.read1(self._CHUNK_SIZE)
File "C:\Python30\lib\io.py", line 994, in read1
self._peek_unlocked(1)
File "C:\Python30\lib\io.py", line 981, in _peek_unlocked
current = self.raw.read(to_read)
File "C:\Python30\lib\io.py", line 575, in read
n = self.readinto(b)
File "C:\Python30\lib\socket.py", line 214, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out |
The traceback shows that the problem is not related to the socket Traceback (most recent call last):
ftp.dir()
=> self.retrlines(cmd, func)
=> return self.voidresp()
=> line = self.getline()
=> line = self.file.readline() (ftplib.py:184)
...
socket.timeout: timed out I don't understand why the readline() blocks. It's maybe related to |
Christopher: Can you paste the full output with debuglevel=3 of Python |
When running scritp with python 2.5.4, got this error. I'll remove the Traceback (most recent call last):
File "C:\python_scripts\python3\candee_processor.py", line 3, in <module>
ftp = ftplib.FTP('ftp.edgecastcdn.net',
user='client1@arcostream.com', passwd='1210184520', timeout=2)
TypeError: __init__() got an unexpected keyword argument 'timeout' Same without the timeout argument: >>>
*cmd* 'CWD chrismahan-675'
*put* 'CWD chrismahan-675\r\n'
*get* '250 CWD command successful\r\n'
*resp* '250 CWD command successful'
*cmd* 'TYPE A'
*put* 'TYPE A\r\n'
*get* '200 Type set to A\r\n'
*resp* '200 Type set to A'
*cmd* 'PASV'
*put* 'PASV\r\n'
*get* '227 Entering Passive Mode (72,21,82,190,228,195).\r\n'
*resp* '227 Entering Passive Mode (72,21,82,190,228,195).'
*cmd* 'LIST'
*put* 'LIST\r\n'
*get* '150 Opening ASCII mode data connection for file list\r\n'
*resp* '150 Opening ASCII mode data connection for file list'
*retr* '-rwxrwxrwx 1 nobody nogroup 3905538 Dec 29 09:51 Bronski
Beat - Why.mp3\r\n'
-rwxrwxrwx 1 nobody nogroup 3905538 Dec 29 09:51 Bronski Beat -
Why.mp3
*retr* '-rwxrwxrwx 1 nobody nogroup 873966 Dec 28 13:53
test9.avi\r\n'
-rwxrwxrwx 1 nobody nogroup 873966 Dec 28 13:53 test9.avi
*retr* '-rwxrwxrwx 1 nobody nogroup 2512653 Dec 29 08:28
test9_lg.wmv\r\n'
-rwxrwxrwx 1 nobody nogroup 2512653 Dec 29 08:28 test9_lg.wmv
*retr* '-rwxrwxrwx 1 nobody nogroup 6549 Dec 29 08:28
test9_lg.wmv.jpg\r\n'
-rwxrwxrwx 1 nobody nogroup 6549 Dec 29 08:28 test9_lg.wmv.jpg
*retr* '-rwxrwxrwx 1 nobody nogroup 1788466 Dec 29 03:04
test9_med.flv\r\n'
-rwxrwxrwx 1 nobody nogroup 1788466 Dec 29 03:04 test9_med.flv
*retr* '-rwxrwxrwx 1 nobody nogroup 6394 Dec 29 03:04
test9_med.flv.jpg\r\n'
-rwxrwxrwx 1 nobody nogroup 6394 Dec 29 03:04 test9_med.flv.jpg
*retr* '-rwxrwxrwx 1 nobody nogroup 1263041 Dec 28 13:53
test9_sm.flv\r\n'
-rwxrwxrwx 1 nobody nogroup 1263041 Dec 28 13:53 test9_sm.flv
*retr* '-rwxrwxrwx 1 nobody nogroup 6465 Dec 28 13:53
test9_sm.flv.jpg\r\n'
-rwxrwxrwx 1 nobody nogroup 6465 Dec 28 13:53 test9_sm.flv.jpg
*retr* ''
*get* '226 Transfer complete\r\n'
*resp* '226 Transfer complete'
>>> |
Update: I requested a test ftp account from edgecast. The tech's response was |
Edgecast.com support created a test ftp account for the purpose of |
Ok, some news about this bug (I tested the ftp test account): the |
Patch: SocketIO.close() decrements the io reference of its socket, so About the FTP server ftp2.edgecastcdn.net, it looks like the server |
Issue bpo-3826 is the same issue and has already patch with 2 unit tests. |
New patch:
TODO: Check all operations on closed _socket, socket or SocketIO and exakrun on IRC: |
I created a separated patch to block operation on closed socket: Issue So I simplified the patch to change on Modules/socketmodule.c and I |
edgecast support said the ftp server is ProFTPD version 1.3.1. |
I'm closing this issue because it's a duplicate of bpo-3826, issue with a |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: