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: Set a timeout in test_urllib2net
Type: Stage: resolved
Components: Library (Lib), Tests Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: orsenthil, vstinner
Priority: normal Keywords: patch

Created on 2010-04-19 12:42 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_urllib2net_timeout.patch vstinner, 2010-04-19 15:00
test_urllib2net_timeout.patch-2 orsenthil, 2010-04-19 19:08
Messages (8)
msg103590 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-04-19 12:42
If an URL doesn't answer, the whole test hung. Many buildbots turned red because an URL (maybe ftp://ftp.kernel.org/pub/linux/kernel/README) didn't answer during few minutes (it works again).

We should add a timeout, eg. 5 minutes. I don't know what to do on timeout: ignore the test? skip the test? Ignore should be fine.
msg103608 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-04-19 15:00
Attached patch sets the timeout to 60 seconds. It writes "<timeout: %s>" % url to stderr on timeout. I don't know better place to write the error. (The test doesn't fail, it just continues to the next URL)
msg103625 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-04-19 19:08
Hello Victor,

The patch looks for fine for a timeout enforcement.

A couple of changes required.

-                if isinstance(err[0], timeout):
+                if isinstance(err[0], socket.timeout):

And, in this portion:

+                try:
+                    with test_support.transient_internet():
+                        buf = f.read()
+                except socket.timeout:
+                    print >>sys.stderr, "<timeout: %s>" % url
                 f.close()
                 debug("read %d bytes" % len(buf))

The last line references, buf. It wont be available if a socket.timeout had happened. So, it can simply be moved to the line below buf = f.read(). Attaching the patch with these changes.

Question: Were you able to simulate a timeout at kernel.org site to test this? If yes, how? I am unable to simulate (by changing the kernel.org:81, kernel42.org etc), it immediately throws a connection refused. ( In general, I could simulate the timeout by urlopen('www.google.com:81', timeout=30) and test the exception) 

As build-bot seems to be hung, a timeout enforcement as the patch accomplishes is fine.
msg103659 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-04-19 23:23
> The last line references, buf. It wont be available if a
> socket.timeout had happened. So, it can simply be moved to 
> the line below buf = f.read(). Attaching the patch with 
> these changes.

Good catch :-)

> Question: Were you able to simulate a timeout at kernel.org 
> site to test this? If yes, how?

I used a firewall rule. On Linux, you can try: iptables -I OUTPUT DROP to drop all output packets (and then iptables -F to remove all rules). It's not reliable, but the test does sometimes fail :-)
msg103678 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-04-20 06:56
Committed revision 80236 in the trunk. The build-bots should not hang now. Shall merge to other branches too.
msg103689 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2010-04-20 09:30
Don't you port the fix to py3k?
msg103690 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-04-20 09:55
Yes, definitely it needs to be ported. I realized that, py3k was in a bad shape at moment.

File "Lib/test/test_urllib2net.py", line 151, in _test_urls
    import logging
File "/home/senthil/python/py3k/Lib/logging/__init__.py", line 43, in <module>
    import threading
File "/home/senthil/python/py3k/Lib/threading.py", line 34, in <module>
    TIMEOUT_MAX = _thread.TIMEOUT_MAX
AttributeError: 'module' object has no attribute 'TIMEOUT_MAX'

This is without the patch in.
I was looking at what was wrong there, and once that is fix, merging this change to py3k would be fine.
msg103692 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2010-04-20 10:48
make distclean erased the problem. :) merged to py3k in r80256 and release31-maint in r80257. Had merged to release26-maint in r80237
History
Date User Action Args
2022-04-11 14:57:00adminsetgithub: 52706
2010-04-20 10:48:15orsenthilsetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg103692

stage: resolved
2010-04-20 09:55:49orsenthilsetmessages: + msg103690
2010-04-20 09:30:28vstinnersetmessages: + msg103689
2010-04-20 06:56:34orsenthilsetassignee: orsenthil
resolution: accepted
messages: + msg103678
2010-04-19 23:23:04vstinnersetmessages: + msg103659
2010-04-19 19:08:48orsenthilsetfiles: + test_urllib2net_timeout.patch-2

messages: + msg103625
2010-04-19 16:20:30vstinnersetnosy: + orsenthil
2010-04-19 15:00:26vstinnersetfiles: + test_urllib2net_timeout.patch
keywords: + patch
messages: + msg103608
2010-04-19 12:42:24vstinnercreate