[Python-Dev] socket.try_reuse_address() (original) (raw)

Giampaolo Rodola' gnewsg at gmail.com
Tue Apr 29 16:43:04 CEST 2008


Maybe it would be better considering Windows CE systems too:

Moreover if the method is called "try_reuse_address" I'd expect that "self._sock.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)" would be placed inside a try/except block.

On 29 Apr, 15:58, Trent Nelson <tnel... at onresolve.com> wrote:

Since the recent changes to networking-oriented tests (issue 2550, r62234 and r62237), I think it's safe to say stability of the test suite on all the non-Windows platforms has improved significantly in this area (I don't recall seeing any socket errors in *nix buildbot logs since those commits).

However, Windows buildbots are still periodically failing.  More specifically, my Windows buildbots are still failing.  One thing that's different about my buildbots is that two are being run at the same time for both trunk and py3k -- one doing an x86 build, the other doing x64 build. Since the changes in the aforementioned revisions, the behaviour of my buildbots has definitely improved -- they no longer completely wedge on testasync(chat|core), mainly due to abolishing all use of SOREUSEADDR as a socket option in any network-oriented tests. However, periodically, they're still dying/failing in a variety of ways -- see relevant log snippets at the end of this e-mail for examples.  I attribute this to the fact that SOREUSEADDR is still set as a socket option in asyncore.py and SocketServer.py.  Basically, SOREUSEADDR should never be set on Windows for TCP/IP sockets.  Using asyncore.py as an example, here are two ways we could handle this: 1. Hard code the Windows opt-out: --- asyncore.py (revision 62509) +++ asyncore.py (working copy) @@ -267,6 +267,8 @@  def setreuseaddr(self):  # try to re-use a server port if possible +        if os.name == 'nt' and self.socket.sockettype != socket.SOCKDGRAM: +            return  try:  self.socket.setsockopt(  socket.SOLSOCKET, socket.SOREUSEADDR, 2. Introduce socket.tryreuseaddress(): --- asyncore.py (revision 62509) +++ asyncore.py (working copy) @@ -266,15 +266,7 @@  self.addchannel(map)  def setreuseaddr(self): -        # try to re-use a server port if possible -        try: -            self.socket.setsockopt( -                socket.SOLSOCKET, socket.SOREUSEADDR, -                self.socket.getsockopt(socket.SOLSOCKET, -                                       socket.SOREUSEADDR) | 1 -                ) -        except socket.error: -            pass +        self.socket.tryreuseaddress() With tryuseaddress implemented as follows: --- socket.py   (revision 62509) +++ socket.py   (working copy) @@ -197,6 +197,10 @@  Return a new socket object connected to the same system resource."""  return socketobject(sock=self.sock) +    def tryreuseaddress(self): +        if not (os.name == 'nt' and self.sock.type != SOCKDGRAM): +            self.sock.setsockopt(SOLSOCKET, SOREUSEADDR, 1) +  def makefile(self, mode='r', bufsize=-1):  """makefile([mode[, bufsize]]) -> file object I prefer the latter as it's cleaner, easier to document and encapsulates what we're trying to do relatively well.  The affected modules would be asyncore.py, SocketServer.py and idlelib/rpc.py.  Thoughts? Regards, Trent. testftplib remoteFailed: [Failure instance: Traceback (failure with no frames): twisted.internet.error.ConnectionLost: Connection to the other side was lost in a non-clean fashion. ] testasynchat test testasynchat failed -- errors occurred; run in verbose mode for details [snip to bottom of log where testasynchat is re-run] 1 test failed: testasynchat 33 tests skipped: test_locale testaepack testapplesingle testcProfile testcommands testcrypt testcurses testdbm testepoll testfcntl testfork1 testgdbm testgrp testioctl testkqueue testmacostools testmhlib testnis testopenpty testossaudiodev testpipes testpoll testposix testpty testpwd testresource testscriptpackages testsignal testsyslog testthreadsignals testwait3 testwait4 testzipfile64 Those skips are all expected on win32. Re-running failed tests in verbose mode Re-running test 'testasynchat' in verbose mode testclosewhendone (test.testasynchat.TestAsynchat) ... ok testemptyline (test.testasynchat.TestAsynchat) ... ok testlineterminator1 (test.testasynchat.TestAsynchat) ... ok testlineterminator2 (test.testasynchat.TestAsynchat) ... ok testlineterminator3 (test.testasynchat.TestAsynchat) ... ok testnoneterminator (test.testasynchat.TestAsynchat) ... ok testnumericterminator1 (test.testasynchat.TestAsynchat) ... ok testnumericterminator2 (test.testasynchat.TestAsynchat) ... ok testsimpleproducer (test.testasynchat.TestAsynchat) ... ok teststringproducer (test.testasynchat.TestAsynchat) ... ok testclosewhendone (test.testasynchat.TestAsynchatWithPoll) ... ok testemptyline (test.testasynchat.TestAsynchatWithPoll) ... ok testlineterminator1 (test.testasynchat.TestAsynchatWithPoll) ... ok testlineterminator2 (test.testasynchat.TestAsynchatWithPoll) ... ok testlineterminator3 (test.testasynchat.TestAsynchatWithPoll) ... ok testnoneterminator (test.testasynchat.TestAsynchatWithPoll) ... ok testnumericterminator1 (test.testasynchat.TestAsynchatWithPoll) ... ok testnumericterminator2 (test.testasynchat.TestAsynchatWithPoll) ... ok testsimpleproducer (test.testasynchat.TestAsynchatWithPoll) ... ok teststringproducer (test.testasynchat.TestAsynchatWithPoll) ... ok testfindprefixatend (test.testasynchat.TestHelperFunctions) ... ok testbasic (test.testasynchat.TestFifo) ... ok testgivenlist (test.testasynchat.TestFifo) ... ok ---------------------------------------------------------------------- Ran 23 tests in 11.812s OK (Note that re-running the test here didn't result in the test failing again.) 1 test failed: testsmtplib Traceback (most recent call last): File "S:\buildbots\python\3.0.nelson-windows\build\lib\threading.py", line 493, in bootstrapinner self.run() File "S:\buildbots\python\3.0.nelson-windows\build\lib\threading.py", line 449, in run self.target(*self.args, **self.kwargs) File "S:\buildbots\python\3.0.nelson-windows\build\lib\test\testsmtplib.py", line 106, in debuggingserver pollfun(0.01, asyncore.socketmap) File "S:\buildbots\python\3.0.nelson-windows\build\lib\asyncore.py", line 132, in poll read(obj) File "S:\buildbots\python\3.0.nelson-windows\build\lib\asyncore.py", line 72, in read obj.handleerror() File "S:\buildbots\python\3.0.nelson-windows\build\lib\asyncore.py", line 68, in read obj.handlereadevent() File "S:\buildbots\python\3.0.nelson-windows\build\lib\asyncore.py", line 390, in handlereadevent self.handleread() File "S:\buildbots\python\3.0.nelson-windows\build\lib\test\testssl.py", line 524, in handleread data = self.recv(1024) File "S:\buildbots\python\3.0.nelson-windows\build\lib\asyncore.py", line 342, in recv data = self.socket.recv(buffersize) File "S:\buildbots\python\3.0.nelson-windows\build\lib\ssl.py", line 247, in recv return self.read(buflen) File "S:\buildbots\python\3.0.nelson-windows\build\lib\ssl.py", line 162, in read v = self.sslobj.read(len or 1024) socket.error: [Errno 10053] An established connection was aborted by the software in your host machine


Python-Dev mailing list Python-... at python.orghttp://mail.python.org/mailman/listinfo/python-dev Unsubscribe:http://mail.python.org/mailman/options/python-dev/python-dev2-garchiv...



More information about the Python-Dev mailing list