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

ftplib behaves oddly if socket timeout is greater than the default #75139

Open
arloclarke mannequin opened this issue Jul 17, 2017 · 5 comments
Open

ftplib behaves oddly if socket timeout is greater than the default #75139

arloclarke mannequin opened this issue Jul 17, 2017 · 5 comments
Labels
3.7 (EOL) end of life topic-IO type-bug An unexpected behavior, bug, or error

Comments

@arloclarke
Copy link
Mannequin

arloclarke mannequin commented Jul 17, 2017

BPO 30956
Nosy @bitdancer, @arloclarke

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:

assignee = None
closed_at = None
created_at = <Date 2017-07-17.23:05:28.615>
labels = ['type-bug', '3.7', 'expert-IO']
title = 'ftplib behaves oddly if socket timeout is greater than the default'
updated_at = <Date 2017-07-18.18:05:10.392>
user = 'https://github.com/arloclarke'

bugs.python.org fields:

activity = <Date 2017-07-18.18:05:10.392>
actor = 'r.david.murray'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['IO']
creation = <Date 2017-07-17.23:05:28.615>
creator = 'arloclarke'
dependencies = []
files = []
hgrepos = []
issue_num = 30956
keywords = []
message_count = 5.0
messages = ['298565', '298567', '298602', '298610', '298611']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'arloclarke']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue30956'
versions = ['Python 3.6', 'Python 3.7']

@arloclarke
Copy link
Mannequin Author

arloclarke mannequin commented Jul 17, 2017

Stack overflow question with full details: https://stackoverflow.com/questions/45150568/python-ftp-socket-timeout-handling

Socket timeout in ftplib can't be handled; a program crash occurs even when the relevant code is wrapped in a general catch-all.

@arloclarke arloclarke mannequin added type-crash A hard crash of the interpreter, possibly with a core dump topic-IO labels Jul 17, 2017
@bitdancer
Copy link
Member

Given:

import socket
from ftplib import FTP
try:
    ftp = FTP('host.i.know.will.hang.com', timeout=4)
except socket.timeout:
    print('caught')

I see 'caught' printed on the console. However, if I increase the timeout to 400, then on both 3.5 tip and 3.6 tip I get a TimeoutError, not a socket.timeout. If I increase the timeout to 4000, I get the TimeoutError in a much shorter time than 4000 seconds.

So, *something* is wrong here. Looking at the code it isn't obvious what.

Here is the traceback:

Traceback (most recent call last):
  File "../p36/temp.py", line 4, in <module>
    ftp = FTP('xxxx', timeout=4)
  File "/home/rdmurray/python/p35/Lib/ftplib.py", line 118, in __init__
    self.connect(host)
  File "/home/rdmurray/python/p35/Lib/ftplib.py", line 153, in connect
    source_address=self.source_address)
  File "/home/rdmurray/python/p35/Lib/socket.py", line 712, in create_connection
    raise err
  File "/home/rdmurray/python/p35/Lib/socket.py", line 703, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

Your traceback is different because your timeout is occurring after the initial connection. Are you sure your socket.timeout is the correct one? You might try printing socket.__file__ to check.

@arloclarke
Copy link
Mannequin Author

arloclarke mannequin commented Jul 18, 2017

Thanks David. Lowering the timeout to below 60s seems to have resolved this issue. Or at least the error isn't being thrown anymore. I don't know why the error couldn't be handled in the first place, however.

@arloclarke arloclarke mannequin closed this as completed Jul 18, 2017
@bitdancer
Copy link
Member

I would like to leave this issue open. It is clear that the behavior for long timeouts does not match the docs, and that should be investigated if someone has the motivation :)

@bitdancer bitdancer reopened this Jul 18, 2017
@bitdancer
Copy link
Member

I changed the title to reflect the problem, but note that I'm *assuming* it is "greater than the default" that is the issue, I haven't actually tested that theory.

@bitdancer bitdancer changed the title ftplib socket timeout can't be handled ftplib behaves oddly if socket timeout is greater than the default Jul 18, 2017
@bitdancer bitdancer added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error and removed type-crash A hard crash of the interpreter, possibly with a core dump labels Jul 18, 2017
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life topic-IO type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant