[New-bugs-announce] [issue11721] socket.accept() with a timout socket creates bogus socket
Kristján Valur Jónsson
report at bugs.python.org
Wed Mar 30 14:17:22 CEST 2011
New submission from Kristján Valur Jónsson <kristjan at ccpgames.com>:
I found this defect at PyCon 2011 after spending a lot of type fidgeting with ssl. The test_ssl.py unittest was using timeout on accept sockets and it was working fine there, but not with the code I was working out. Turns out that _ssl.py resets the timeout state of sockets, but not regular sockets.
In short: If you have a socket with settimeout(1), then accept a connection on it, the new socket will have gettimeout()==None, but its state will still (internally) be non-blocking. The attached script demonstrates the issue.
This is an issue with all versions of python from 2.5 upwards.
There are basically two things we can do to fis this:
1) retain gettimeout()=None but internally make sure we set the resulting socket to blocking mode
2) have the accepted socket inherit the timeout properties of the parent socket properly, and so inherit its timeout value too.
Number 2 is more in line with expected BSD socket behaviour that sockets at least inherit the non-blocking attribute of their parent socket.
title: socket.accept() with a timout socket creates bogus socket
versions: Python 2.5, Python 2.6, Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4
Added file: http://bugs.python.org/file21473/bug.py
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce