Issue 1515839: socket timeout inheritance on accept (original) (raw)

Created on 2006-07-02 13:05 by kirma, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg60934 - (view) Author: Jari Kirma (kirma) Date: 2006-07-02 13:05
Socket objects returned by socket.accept() get their blocking and timeout setting(s) from socket.defaulttimeout. This can be in conflict with reality of the (non-)blocking mode of actual OS-level socket they use. For instance, FreeBSD sockets inherit their socket options from the parent socket on accept(2) system call, and thus a socket object with defined socket timeout and default defaulttimeout returns a socket object that seems to be blocking, non-timeout socket, but the underlying OS socket is actually in nonblocking mode, which can cause read/recv and write/send operations to behave unexpectedly. Even worse, POSIX/SUSv3 doesn't explicitly require socket option inheritance (http://www.opengroup.org/onlinepubs/009695399/functions/accept.html). The socket library should explicitly set the socket timeout mode (either to defaulttimeout, or with accompanying documentation, inherit the value from socket object passed to accept()) and modify the OS socket options accordingly.
msg60935 - (view) Author: Jari Kirma (kirma) Date: 2006-07-02 13:23
Logged In: YES user_id=1548868 Making socket objects behave reliably can be achieved simply by always calling internal_setblocking in init_sockobject of socketmodule.c, but this causes overhead of one system call on all socket creations. Alternatively one could call internal_setblocking from sock_accept if parent socket has timeouts/nonblocking mode enabled. This should work in under all reasonable scenanarios and avoid system call overhead on majority of cases.
msg113368 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2010-08-09 03:40
I am sorry this has not gotten any response. There does not seem to currently be anyone specifically working on the socket module, so this got lost among hundreds of other feature requests.
msg124960 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-12-31 09:32
The problem you have reported here was later independently reported in Issue7995 where a possible fix has been proposed. Suggest adding yourself to the nosy list of that issue to monitor current status.
History
Date User Action Args
2022-04-11 14:56:18 admin set github: 43596
2010-12-31 09:32:01 ned.deily set status: open -> closednosy: + ned.deilymessages: + superseder: On Mac / BSD sockets returned by accept inherit the parent's FD flagsresolution: duplicate
2010-08-09 03:40:22 terry.reedy set nosy: + terry.reedymessages: + versions: + Python 3.2, - Python 3.1, Python 2.7
2009-03-30 05:57:09 ajaksu2 set stage: test neededtype: enhancementcomponents: + Extension Modulesversions: + Python 3.1, Python 2.7, - Python 2.5
2006-07-02 13:05:04 kirma create