Index: Misc/ACKS =================================================================== --- Misc/ACKS (revision 87629) +++ Misc/ACKS (working copy) @@ -131,6 +131,7 @@ Daniel Calvelo Tony Campbell Brett Cannon +Justin Cappos Mike Carlton Terry Carroll Lorenzo M. Catucci Index: Misc/NEWS =================================================================== --- Misc/NEWS (revision 87629) +++ Misc/NEWS (working copy) @@ -20,6 +20,10 @@ Library ------- +- Issue #7995: Fix on Unix systems except Linux that the socket + returned from socket.accept() must not inherit the listening socket's file + status flags. Patch by Ross Lagerwall. + - Issue #10801: In zipfile, support different encodings for the header and the filenames. Index: Lib/test/test_socket.py =================================================================== --- Lib/test/test_socket.py (revision 87629) +++ Lib/test/test_socket.py (working copy) @@ -976,6 +976,21 @@ def _testInitNonBlocking(self): pass + def testInheritFlags(self): + self.serv.settimeout(10) + try: + conn, addr = self.serv.accept() + message = conn.recv(len(MSG)) + finally: + conn.close() + self.serv.settimeout(None) + + def _testInheritFlags(self): + time.sleep(0.1) + self.cli.connect((HOST, self.port)) + time.sleep(0.5) + self.cli.send(MSG) + def testAccept(self): # Testing non-blocking accept self.serv.setblocking(0) Index: Modules/socketmodule.c =================================================================== --- Modules/socketmodule.c (revision 87629) +++ Modules/socketmodule.c (working copy) @@ -1700,6 +1700,13 @@ if (newfd == INVALID_SOCKET) return s->errorhandler(); +#if defined(HAVE_FCNTL_H) && defined(O_NONBLOCK) && !defined(__Linux__) + /* Try unset O_NONBLOCK if it's inherited. */ + int st_flag = fcntl(newfd, F_GETFL, 0); + if (st_flag != -1) + fcntl(newfd, F_SETFL, st_flag & ~O_NONBLOCK); +#endif + sock = PyLong_FromSocket_t(newfd); if (sock == NULL) { SOCKETCLOSE(newfd);