Skip to content
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

FTPFS: EOFError in listdir #292

Closed
efuce opened this issue Jun 6, 2019 · 5 comments · Fixed by #315
Closed

FTPFS: EOFError in listdir #292

efuce opened this issue Jun 6, 2019 · 5 comments · Fixed by #315
Labels

Comments

@efuce
Copy link

efuce commented Jun 6, 2019

Hello,

I am new to pyfilesystem, so please excuse if i might have missed something. From what i can understand from the documentation pyfilesystem2 translates exceptions from the underlying filesystem into a common set of exceptions.

There seems to be a corner case for ftpfs where it might raise EOFError in listdir if the server forcefully closes the connection during the operation. This exception seems to be coming from the underlying ftplib.

@willmcgugan
Copy link
Member

PyFilesystem methods should translate all exceptions to the common exceptions.

So if listdir is throwing an EOFError, that would be considered a bug. If you have a traceback I could have a look at it, or a PR is always welcome.

@willmcgugan willmcgugan added the bug label Jun 8, 2019
@efuce
Copy link
Author

efuce commented Jun 8, 2019

Traceback:

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    fs.listdir('.')
  File "/usr/lib/python3.7/site-packages/fs/wrapfs.py", line 152, in listdir
    dir_list = _fs.listdir(_path)
  File "/usr/lib/python3.7/site-packages/fs/ftpfs.py", line 628, in listdir
    dir_list = [info.name for info in self.scandir(_path)]
  File "/usr/lib/python3.7/site-packages/fs/ftpfs.py", line 628, in <listcomp>
    dir_list = [info.name for info in self.scandir(_path)]
  File "/usr/lib/python3.7/site-packages/fs/ftpfs.py", line 721, in _scandir
    lambda l: lines.append(_decode(l, self.ftp.encoding)),
  File "/usr/lib/python3.7/ftplib.py", line 467, in retrlines
    resp = self.sendcmd('TYPE A')
  File "/usr/lib/python3.7/ftplib.py", line 273, in sendcmd
    return self.getresp()
  File "/usr/lib/python3.7/ftplib.py", line 236, in getresp
    resp = self.getmultiline()
  File "/usr/lib/python3.7/ftplib.py", line 222, in getmultiline
    line = self.getline()
  File "/usr/lib/python3.7/ftplib.py", line 210, in getline
    raise EOFError
EOFError

@lurch
Copy link
Contributor

lurch commented Jun 8, 2019

Looks like that's coming from https://github.com/python/cpython/blob/master/Lib/ftplib.py#L210

There appears to be a mismatch as the ftplib docs say "This set includes the four exceptions listed above as well as OSError." but the ftplib code says all_errors = (Error, OSError, EOFError) ☹️

@dargueta
Copy link
Contributor

dargueta commented Jul 26, 2019

Error is a superclass of the four exceptions so the documentation is correct. However, it looks like we're not catching two of those exceptions, nor OSError.

I've tried catching OSError but this seems to cause some trouble because it's the superclass of socket.error and for some reason changing the order of the except statements isn't working for me.

Update

From the Python docs:

Changed in version 3.3: Following PEP 3151, this class was made an alias of OSError.

dargueta pushed a commit to dargueta/pyfilesystem2 that referenced this issue Jul 26, 2019
@dargueta dargueta mentioned this issue Jul 26, 2019
9 tasks
willmcgugan pushed a commit that referenced this issue Jul 28, 2019
* Handle EOFError (closes #292)

* Update CHANGELOG and CONTRIBUTORS
@lurch
Copy link
Contributor

lurch commented Sep 16, 2019

There appears to be a mismatch...

python/cpython#15026
😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants