Opened 5 years ago
Last modified 5 years ago
#103 new enhancement
Error `open`ing new file-like objects when a connection is timed-out but not yet closed.
Reported by: | ftputiluser | Owned by: | schwa |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | Library | Version: | |
Keywords: | Cc: | pengyu@… |
Description
Here's the sample stack trace:
File "build/bdist.linux-x86_64/egg/ftputil/host.py", line 195, in open File "build/bdist.linux-x86_64/egg/ftputil/host.py", line 166, in _available_child File "/usr/lib/python2.7/ftplib.py", line 583, in pwd resp = self.sendcmd('PWD') File "/usr/lib/python2.7/ftplib.py", line 249, in sendcmd return self.getresp() File "/usr/lib/python2.7/ftplib.py", line 215, in getresp resp = self.getmultiline() File "/usr/lib/python2.7/ftplib.py", line 201, in getmultiline line = self.getline() File "/usr/lib/python2.7/ftplib.py", line 191, in getline if not line: raise EOFError exceptions.EOFError:
The reason might be that the server has already seen the connection as a timed-out one, but not yet closed it.
Note: See
TracTickets for help on using
tickets.
Thanks for entering this ticket. :-)
Replying to ftputiluser:
Assuming this is the reason for the stack trace:
EOFError
would happen most of the time in the lines you have in the stack trace.I just did a web search and found this interesting discussion on StackOverflow. Together with the information in CPython's ticket 148036 that
EOFError
is contained inftplib.all_errors
it appears that ftputil is already implicitly catchingEOFError
s in its context managersftplib_error_to_ftp_os_error
andftplib_error_to_ftp_io_error
inftputil.error
.As it happens,
_available_child
uses a directhost._session.pwd()
call (where_session
usually is anftplib.FTP
instance) instead of the context managers.I guess I'll use the
ftplib_error_to_ftp_os_error
context manager in_available_child
and consider the child session unusable if the context manager gives me anFTPOSError
.TemporaryError
andPermanentError
inherit fromFTPOSError
, so this would also implicitly catch theftplib.error_temp
I'm catching now in_available_child
.