This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: create_connection() recasts timeout errors
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: exarkun, facundobatista, giampaolo.rodola, pitrou
Priority: normal Keywords: patch

Created on 2010-09-07 19:50 by pitrou, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
createconn.patch pitrou, 2010-09-07 20:20
Messages (4)
msg115798 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-07 19:50
When you call socket.create_connection() and it fails because it hits the socket timeout, the socket.timeout error is recast as a generic socket.error, which makes analyzing the failure more difficult (also, it means the "errno" attribute is lost for other types of errors):

>>> socket.setdefaulttimeout(0.000001)
>>> s = socket.socket()
>>> s.connect(("www.yahoo.fr", 80))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.timeout: timed out
>>> socket.create_connection(("www.yahoo.fr", 80))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/antoine/py3k/__svn__/Lib/socket.py", line 319, in create_connection
    raise err
socket.error: timed out
msg115802 - (view) Author: Giampaolo Rodola' (giampaolo.rodola) * (Python committer) Date: 2010-09-07 20:17
On Ubuntu 10.04:

giampaolo@ubuntu:~/svn/python-3.2$ ./python 
Python 3.2a1+ (py3k:84457, Sep  3 2010, 20:18:38) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> import socket
>>> socket.setdefaulttimeout(0.000001)
>>> s = socket.socket()
>>> s.connect(("www.yahoo.fr", 80))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.timeout: timed out
>>>
msg115804 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-07 20:20
Here is a patch.
msg115806 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2010-09-07 21:06
Patch committed in r84598. Needs backporting to 3.1 and 2.7.
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54001
2010-09-07 21:40:36pitrousetstatus: pending -> closed
2010-09-07 21:06:20pitrousetstatus: open -> pending
resolution: fixed
messages: + msg115806

stage: needs patch -> resolved
2010-09-07 20:20:57pitrousetfiles: + createconn.patch
keywords: + patch
messages: + msg115804
2010-09-07 20:17:43giampaolo.rodolasetmessages: + msg115802
2010-09-07 19:50:12pitroucreate