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

socket timeouts produce wrong errors in win32 #38210

Closed
glchapman mannequin opened this issue Mar 24, 2003 · 3 comments
Closed

socket timeouts produce wrong errors in win32 #38210

glchapman mannequin opened this issue Mar 24, 2003 · 3 comments
Labels
stdlib Python modules in the Lib dir

Comments

@glchapman
Copy link
Mannequin

glchapman mannequin commented Mar 24, 2003

BPO 708927

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 = <Date 2004-06-02.15:09:46.000>
created_at = <Date 2003-03-24.17:59:37.000>
labels = ['library']
title = 'socket timeouts produce wrong errors in win32'
updated_at = <Date 2004-06-02.15:09:46.000>
user = 'https://bugs.python.org/glchapman'

bugs.python.org fields:

activity = <Date 2004-06-02.15:09:46.000>
actor = 'glchapman'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2003-03-24.17:59:37.000>
creator = 'glchapman'
dependencies = []
files = []
hgrepos = []
issue_num = 708927
keywords = []
message_count = 3.0
messages = ['15252', '15253', '15254']
nosy_count = 2.0
nosy_names = ['glchapman', 'troels']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue708927'
versions = ['Python 2.3']

@glchapman
Copy link
Mannequin Author

glchapman mannequin commented Mar 24, 2003

Here's a session:

Python 2.3a2 (#39, Feb 19 2003, 17:58:58) [MSC v.1200 
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import socket
>>> socket.setdefaulttimeout(0.01)
>>> import urllib
>>> urllib.urlopen('http://www.python.org')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "c:\Python23\lib\urllib.py", line 76, in urlopen
    return opener.open(url)
  File "c:\Python23\lib\urllib.py", line 181, in open
    return getattr(self, name)(url)
  File "c:\Python23\lib\urllib.py", line 297, in open_http
    h.endheaders()
  File "c:\Python23\lib\httplib.py", line 705, in endheaders
    self._send_output()
  File "c:\Python23\lib\httplib.py", line 591, in 
_send_output
    self.send(msg)
  File "c:\Python23\lib\httplib.py", line 558, in send
    self.connect()
  File "c:\Python23\lib\httplib.py", line 798, in connect

IOError: [Errno socket error] (2, 'No such file or directory')
>>> urllib.urlopen('http://www.python.org')
< SNIP >

IOError: [Errno socket error] (0, 'Error')

Looking at socketmodule.c, it appears internal_connect
must be taking the path which (under MS_WINDOWS)
calls select to see if there was a timeout. select must
be returning 0 (to signal a timeout), but it apparently
does not call WSASetLastError, so when set_error is
called, WSAGetLastError returns 0, and the ultimate
error generated comes from the call to
PyErr_SetFromErrNo. Perhaps in this case
internal_connect should itself call WSASetLastError
(with WSAETIMEDOUT rather than
WSAEWOULDBLOCK?).

The reason I ran into this is I was planning to convert
some code which used the timeoutsocket module under
2.2. That module raises a Timeout exception (which the
code was catching) and I was trying to figure out what
the equivalent exception would be from the normal
socket module. Perhaps the socket module should
define some sort of timeout exception class so it would
be easier to detect timeouts as opposed to other socket
errors.

@glchapman glchapman mannequin closed this as completed Mar 24, 2003
@glchapman glchapman mannequin added the stdlib Python modules in the Lib dir label Mar 24, 2003
@glchapman glchapman mannequin closed this as completed Mar 24, 2003
@glchapman glchapman mannequin added the stdlib Python modules in the Lib dir label Mar 24, 2003
@troels
Copy link
Mannequin

troels mannequin commented Jun 2, 2004

Logged In: YES
user_id=32863

I think this may be fixed. I wasn't able to reproduce the
problem with Python 2.3.4 on Windows XP SP1.

Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> import socket
>>> socket.setdefaulttimeout(0.01)
>>> import urllib
>>> urllib.urlopen('http://www.python.org')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "C:\Program Files\Python23\lib\urllib.py", line 76,
in urlopen
    return opener.open(url)
  File "C:\Program Files\Python23\lib\urllib.py", line 181,
in open
    return getattr(self, name)(url)
  File "C:\Program Files\Python23\lib\urllib.py", line 297,
in open_http
    h.endheaders()
  File "C:\Program Files\Python23\lib\httplib.py", line 712,
in endheaders
    self._send_output()
  File "C:\Program Files\Python23\lib\httplib.py", line 597,
in _send_output
    self.send(msg)
  File "C:\Program Files\Python23\lib\httplib.py", line 564,
in send
    self.connect()
  File "C:\Program Files\Python23\lib\httplib.py", line 548,
in connect
    raise socket.error, msg
IOError: [Errno socket error] timed out

Repeatedly calling the code below gives the same exception
and backtrace every time.
>>> urllib.urlopen('http://www.python.org')

@glchapman
Copy link
Mannequin Author

glchapman mannequin commented Jun 2, 2004

Logged In: YES
user_id=86307

I agree that it has been fixed. I think the timeout parameter
to internal_connect was not there for 2.3a2 (but Sourceforge
won't let me connect to the web CVS right now, so I'm not
sure). Anyway, since internal_connect sets timeout to true
in this case, the correct error is generated by sock_connect.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

0 participants